This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
linux:backup_and_restore [2012/03/19 14:17] Joel Dare |
linux:backup_and_restore [2020/06/01 22:53] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Backup and Restore a Linux System ====== | ||
+ | **//I have NOT gotten this to actually work. These are instructions I've pulled from various resources. I imagine they can be made to work, but I haven't figured it out yet.//** | ||
+ | |||
+ | I was trying all sorts of backup options on my system recently. I wanted to backup my entire system and restore it in a virtual machine. I looked at Ghost 4 Linux, Clonezilla, and others. For some reason, none of that stuff was working for me. Finally, I came across a [[http://ubuntuforums.org/showthread.php?t=35087|thread]] that mentioned how to backup by simply tarring everything. | ||
+ | |||
+ | Here's the backup command. | ||
+ | |||
+ | tar cvpzf backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys --exclude=/media --exclude=/backup / | ||
+ | | ||
+ | There is also some mention from other users that you should exclude /dev and /sys. The original poster, however, mentions that there are problems with excluding those and including them doesn't seem to hurt. | ||
+ | |||
+ | Once you have your backup, here's how to restore it. //Be careful, this overwrites all files on your hard drive with those in the backup.// | ||
+ | |||
+ | tar xvpfz backup.tgz -C / | ||
+ | | ||
+ | If you are restoring onto a different system or onto a virtual machine then Grub may have exploded. I found the [[https://help.ubuntu.com/community/Boot-Repair#Getting_Boot-Repair|Boot-Repair documentation]] helpful to restore my system from that state. | ||
+ | |||
+ | ====== Other Thoughts ====== | ||
+ | |||
+ | I probably should have excluded grub or some part of grub in order to prevent messing it up. My case was unique, however, because I was restoring to a different machine (a VM in my case). | ||
+ | |||
+ | I also excluded ///home// because I back it up separately. | ||
+ | |||
+ | One observation I made is that the gziped file was slightly larger than my hard drive. I actually expected it to be slightly smaller, since it's compressed. That was because I created the gzip file on a drive mounted in /media and I did not exclude /media when I did my backup. I've added that exclusion to the backup process now. Make sure you exclude the file or directory that you backup to. | ||
+ | |||
+ | You can also exclude the 'z' option and change the filename from '.tgz' to '.tar' to skip using gzip on the backup. Sometimes disk space is cheap. I tried it both ways and it actually seemed faster when I used gzip; probably because disk speed was my bottle neck. At first I thought this might help me, but it didn't. | ||
+ | |||
+ | There is also a great [[https://help.ubuntu.com/community/BackupYourSystem/TAR|Ubuntu article]] about various ways to do the backup. Doing it across a network was particularly useful in my situation. | ||
+ | |||
+ | Here's the final command that I ran to create the backup. Your command will vary from this and it's here only as a reference. | ||
+ | |||
+ | sudo tar -cvpzf /media/FreeAgent\ Kay/backup.tgz --one-file-system --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/backup --exclude=/home / > ~/backup.log & | ||
+ | | ||
+ | ====== Using rsync Instead ====== | ||
+ | |||
+ | Instead of using tar and gzip you could copy all the files to a destination. This will leave them | ||
+ | |||
+ | sudo rsync -azv --progress --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/backup --exclude=/dev --exclude=/export --exclude=/media --exclude=/mnt --exclude=/tmp / /media/FreeAgent\ Kay/Backup/macubuntu/ |