LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   making scheduled backup image (http://www.linuxquestions.org/questions/linux-newbie-8/making-scheduled-backup-image-715161/)

digity 03-28-2009 04:07 PM

making scheduled backup image
 
How do I go about making a backup image (of just the used space, not the whole drive) of my Ubuntu 8.10 box and having it do this weekly?

TB0ne 03-28-2009 05:10 PM

Quote:

Originally Posted by digity (Post 3490931)
How do I go about making a backup image (of just the used space, not the whole drive) of my Ubuntu 8.10 box and having it do this weekly?

Well, there are several ways. You could use a bare-metal recovery tool, like mkcdrec, systemimager, or mondoarchive, which will create a bootable ISO image, suitable for recovering a system if the hard drive dies.

You could use tar to just grab all the files, and shovel them onto a tape/CD/DVD/whatever, so you can read just one file off if needed, or use network backup tools, to backup to a central server.

No matter which you need, CRON can run the job whenever you tell it to. What kind of backup do you want? To what media? What are your backup goals (just need files? Bare-metal?)??

i92guboj 03-28-2009 05:32 PM

I'd just use tar with gzip compression (bzip2 is quite slow and cpu intensive for such a big backup, though you can use it if you want a smaller backup, though in that case I'd just use 7z). Be sure to read the tar man page, and look specially at the --exclude option which will allow you to exclude dirs like /tmp, /var/tmp, /proc, /dev, /mnt, /media and /sys.

You could also use dd to get a disk image, kind of like a ghost image. If you choose to do so, first make sure to zero out the empty part of the disk first, so the image can be compressed much more effectively. That can be done with this command:

Code:

dd if=/dev/zero of=/tmp/foo bs=4096
It will eventually abort, once the disk is full. Then you can remove /tmp/foo.

To run whatever script weekly, you can put it in /etc/cron.weekly

digity 03-28-2009 08:29 PM

yes, my hard drive died and i want a bare-metal backup to simply restore/clone the most recent image to disk. i'd like to store the backup images on an external drive. is this actually possible?

i92guboj 03-28-2009 09:41 PM

Quote:

Originally Posted by digity (Post 3491100)
yes, my hard drive died and i want a bare-metal backup to simply restore/clone the most recent image to disk. i'd like to store the backup images on an external drive. is this actually possible?

Of course. Cron scripts are run as root, so the same script can be used to mount the drive somewhere, copy the files to the correct place and then unmount the drive again.

jschiwal 03-28-2009 09:49 PM

If you use "df" you can calculate the amount of free space and use that to calculate the size of a zeroed file. Then delete the file. Now if you use dd to create an image, it will compress better.

Make sure that the external drive uses a filesystem that can hold large files. If you use ieee1394 or even better eSATA, it will be a lot faster.

If you don't compress the image, one trick you could use is to mount the partitions on the image and sync files to it. This will give you the convenience of a fast bare metal restore, in the case of an emergency, while keeping the image up to date.

Look at the info manual for tar. You can use it to easily transport files to a mounted partition:

tar -C / -g timestamp -cf - /usr /home /var | tar -C /mnt/backupdir -xvf - >logfile
This will perform incremental backups, extracting the files to the destination.
The /mnt/backupdir could be the mounted image itself. The first time you run it, it will backup all files. The next time, only new files.

Something to play around with anyway.


All times are GMT -5. The time now is 04:13 AM.