Hack 60 Backup and Restore

 < Day Day Up > 

figs/moderate.gif figs/hack60.gif

Use the classic tar command with Knoppix to quickly back up and restore important files .

If you have just gone through a filesystem repair unsuccessfully, then you probably have lost some files. No problem. You can just restore them from your backup. If you don't back up all of your important files, then there's no time like the present to start. Knoppix comes with the venerable tar command, which is used by system administrators to back up important files, and this hack covers using tar to back up and restore a system.

Generally, you want to run tar directly from the machine you are backing up, as opposed to using a rescue CD, so that you don't have to take down the server each time you need to refresh the backup. Although sometimes you might be in a situation where you want a complete backup of a system that has many files in a constant state of flux, you don't want any of the files to change while you are backing them up. You also usually run tar to restore lost files from the running machine itself, but in the situation that the missing files are preventing the machine from booting at all, you might need to make use of a rescue disk like Knoppix to restore the important files to the system so it can boot.

6.10.1 Back Up

Tar has many options, but the basics of creating a backup are pretty simple to remember. First, you should back up the /etc directory. On most Linux systems, /etc stores only text files, which compress to a very small size . If you have worked hard to configure a program and you delete or break that configuration, it can be upsetting and time-consuming to replace. To back up the /etc directory from a root partition that you have mounted on /mnt/hda1 , you should change to the /mnt/hda1 directory and issue the following command:

 knoppix@tty1[hda1]$  sudo tar cvzf /home/knoppix/etc.tar.gz etc/  

Tar outputs the files it is backing up, and you should find a new file, etc.tar.gz , in your /home/knoppix directory. Now, if you are backing up from Knoppix, you do not want to back up to your ramdisk , but instead want to back up to another mounted partition or over the network to another machine. As in [Hack #48] , you can pipe tar to ssh to save to a remote file, as in:

 knoppix@tty1[hda1]$  sudo tar cvzf - etc/  ssh username@192.168.0.2     "cat > /home/  username    /etc.tar.gz"  

6.10.2 Restore

To restore from this archive, replace the -c option with x in the previous command line; otherwise, the standard command is the same. Because the command is so similar, be careful that you restore when you want to restore and create when you want to create; otherwise , you might overwrite your backup instead of restoring to it. Mount the filesystem you want to restore to with read/write permissions, cd to the mounted directory, and run:

 knoppix@tty1[hda1]$  sudo tar xvzf /home/knoppix/etc.tar.gz  

Tar extracts the files into the current directory and overwrites any duplicate files it finds. If you pipe tar to ssh to save to a remote file, cd to the mounted directory and reverse the pipe:

 knoppix@tty1[hda1]$  ssh username@192.168.0.2   "cat > /home/username/etc.tar.gz"  sudo tar xvfz -  

6.10.3 Back Up and Restore a Full Partition

You can also use tar to back up an entire partition to a remote location or another mounted filesystem. First, mount the filesystem, cd to it, and then use a dot (.) to specify the current directory instead of etc/ . If you are backing up a large filesystem, you should be backing it up to another mounted filesystem, such as /mnt/hdb1 :

 knoppix@tty1[hda1]$  sudo tar cvzf  /mnt/hdb1/hda1.tar.gz    ./  

Replace /mnt/hdb1 with the mounted filesystem to which to save this archive. To save a backup over the network, you can pipe tar to ssh with this command:

 knoppix@tty1[hda1]$  sudo tar cvzf - ./  ssh username@192.168.0.2   "cat >  /home/username/hda1.tar.gz    "  

To restore, mount the filesystem you wish to restore, cd to it, and run the same command used to restore from etc.tar.gz . If you only want to restore a particular directoryfor instance, /home then specify that directory on the command line like so:

 knoppix@tty1[hda1]$  sudo tar xvzf  /mnt/hdb1/hda1.tar.gz    home/  

Tar is an old archival tool but still does a great job for back up and recovery in most circumstances. With these basic backup and recovery options, you can take a Knoppix CD to any machine, and back up or recover important files quickly with consistent results and without worrying about backed up or restored files being written to by other programs in the process.

 < Day Day Up > 


Knoppix Hacks. 100 Tips and Tricks
Knoppix Hacks. 100 Tips and Tricks
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 166

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net