FOLLOWING IS A SOLUTION TO AUTOMATING PARTIMAGE with CRON. I really wanted to backup a local machine to my NAS server and finally got it working. A few weeks ago, I posted an interim script as a response to jrios post
, but the following script is more recent and has some important changes. Here's my updated script with extensive notes:
Code: Select all
# Script to backup a partition image to a remote server -- "slug"
# Reguires partimage on the client and partimaged on the server (runs as daemon)
# Evidently requires the same version (some users report this).
# Log file is /var/log/partimage/partimage-debug.log
# A list of Option descriptions and Notes follows
# Added so cron will run script
set > /tmp/cron.environment
# The target partition must be unmounted or partimage will fail
umount /dev/sdb6 > /dev/null 2>&1;
# Here is the "fully batch" partimage script.
partimage --server=slug --port=4025 --username=myname --password=secretpassword --compress=1 --nodesc --finish=3 --debug=3 --fully-batch x=y save /dev/sdb6 /home/bak/ws/kubuntu_ws/images/kub-ws_$Today.gz > /dev/null 2>&1 &&
# Option descriptions:
# --compress=1 compress using gzip: fast and small image file (default)
# --nodesc don't ask any description for the image file
# --finish=3 quit
# --debug=3 debug level; default is 1
# --fully-batch this option works by adding a dummy follower as in "--fully-batch x=y"
# for remote target, must use SSL (the --nossl option will make script fail)
# umount command must end with ";" and not "&&" or it will fail
Please note, the "fully-batch" mode uses the -B or --fully-batch flag, but must have a dummy follower like "x=y" (see the code above). The code " > /dev/null 2>&1" at the end will prevent any terminal verbage if the script is run directly. If you remove it, the script will still run and give you on-screen progress feedback, but this is not desirable when run as a cron job.
The script ran successfully from "/etc/crontab" as root user with the full path-to-script. However a "root crontab" (#crontab -e) failed possibly because it lacked ENV variables that were present in "/etc/crontab"
It took lots of testing for me to get this to work, so I set up a temporary ramdisk test partition using info found on
Tim Abel's blog
. If you try my script, you will likely have to do several tests as well. When the "fully-batch" mode fails in cron, it will do so w/o helpful feed-back, so it's useful to test it at several stages: 1) as a direct command line entry (be sure to remove the "> /dev/null 2>&1" ending to get useful feedback); if that works, then 2) as an "at" job set to run 1 minute from now ("> /dev/null 2>&1" back in); and finally 3) as a cron job. Your system probably differs from my debian-sid system, so ymmv.
Finally, is it really useful to automate partimage this way? Yes and no! First it requires that you have a dual-boot client, because you must be booting into one partition, while partimage works on the second, unmounted one. Second, the most important time to do a backup partition image is just before doing something major on your machine, like a serious dist-upgrade, or making other major changes. This can't be scheduled. Instead I would invoke the script manually, or more probably just do a normal interactive partimage session and save the image locally to my data partition. This is much faster, and safe unless I planned to swap out my hd or something similar. Scheduling partimage is most useful when one has a slow NAS device (like me) or has many machines to backup and you want to do this off hours.
Backing up a 3.7 GB linux root partition over the network to my Linksys NSLU2 (slug) takes about 65 minutes. Saving the same partition locally takes about 15 minutes. My strategy is to set up a cron job every 2-3 weeks on a certain night, run the script, and boot the alternate partition the next night and save the first partition. Another option might be to simply run my script as a "at" job on a certain night when I leave my machine on. Before major system changes I'll run partimage manually and locally as I've done in the past.
As most of you are aware, partimage does not seem to be actively developed, but it is still a very useful program. I have used it a number of times to restore partitions that I have borked, and it always worked perfectly. I'm not a programmer, so if you have issues with this script, you're on your own. Hope this is useful for others!