I'm trying to implement the easy to maintain backup solution for our local linux server. The goal is to be able to restore the whole system from image file.
What I am thinking of is just to issue following script with cron
FILENAME=`date +%F`.bak
dd if=/dev/sda | bzip > /media/remote_backups/$FILENAME
The problem is that this script should be run in special environment - when only basic services work and no filesystems are mounted.
So, the question is: Is it possible to reboot the server by cron, for example, weekly, and then not boot normal mode, but some kind of "special" mode, when nothing loads, except:
- mount remote partition for backups at /media/remote_backups/
- execute dd as previously described
dd really isn't the best solution for this. You should probably look into something like rsync if you want "Quick-and-Dirty Backups." Otherwise, look into a product like Bacula to do a more full-featured backup.
With rsync, you will have file backups. In the case of a total failure, you would need to reinstall linux and then copy the rsync'd files back from the remote location.
With bacula, it does a full bare-metal backup of the system, so you can restore the entire system OS and all of your user files.
See this article for a comprehensive document explaining bare metal recovery with Bacula.
The only easy-to-main backup solution is one that's properly done.
Spend the time to implement bacula or amanda properly and you'll avoid utter disaster.
The only thing that you accomplish above is protecting from drive failure. There's much better ways of doing so - such as mirroring the drive.
Simple answer - you can do what you want by combining some tools as
grub-reboot - set the default boot entry for GRUB, for the next boot only
and starting system in some special runlevel (or init= kernel boot param) where custom script execute dd command. Don't do that!Please consider tools like:
as they can work on mounted filesystem or at least use partimage instead of dd.
Only used blocks are copied and stored into an image file. You can copy data over network (with SSL) and it has many more features.