Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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?)??
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:
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
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.