In this post, I would like to introduce the easiest way to backup and restore the Ubuntu system from my experiences.For more information about backup and restore you can see this post
I am usually doing crazy with my system so it is really necessary to backup the system file before dong such things 🙂
The basic idea is using Tar command. I recommend to backup your system and your personal data separately to avoid the very big backup files and the system file is more important than anything else.
The basic command is:
sudo tar cvpjf backup.tar.bz2 --exclude=/sys /
We should exclude some directories because of some reasons:
- I usually mount other partions under /media directory, but someone they usually mount under /mnt directory. So we should exclude /media and /mn.
- Folder: /var/cache/apt/archives we should remove from backup file because it stores the cache apt files, we don’t need to make the backup file smaller. After several days, if you forget to delete those files, your backup file will get bigger.
- Folder: /home we should exclude because we will store the personal data separately.
- Foder /tmp we can exclude because it stores the temp files only.
- Of course, the backup file before: backup.tar.bz2
Finally, we get the backup commands are: ( I include all necessary commands also)
sudo tar cvpjf backup.tar.bz2 --exclude=/proc --exclude=/lost+found \ --exclude=/backup.tar.bz2 --exclude=/var/cache/apt/archives \ --exclude=/mnt --exclude=/media --exclude=/home --exclude=/tmp --exclude=/sys /
So just copy those commands and paste on your terminal by using the hotkey: Ctr + Alt + V
For backuping your home data, you can do the same way without or with exclude some directories like:
– Browse to the user directory, let’s assume /home/ngohaibac
– Backup by using tar command and exclude some folders I don’t want to backup
sudo tar cvpjf backup_home.tar.bz2 --exclude=~/store --exclude=~/backup_home.tar.bz2 .
To get backme the system at the backup time, I recommend you a good way to do:
Boot your system using Live Ubuntu CD and delete all directories: /usr, /var, /etc, /bin in the Ubuntu partion. You can use the command like: sudo rm -fr /media/ubuntu_mout_point/usr
Restore all files by using tar command:
– Browse to that partion: let’s assume /media/disk
– Restore all data:
sudo tar xvpfj backup.tar.bz2 -C .
Wait for a moment, and reboot your system, now you can get your system again.