Backup today can be a PITA. It takes too long, and too much work to automate. That’s what makes this single line backup script one of my favorites. It creates a compressed DD image a remote server in the form of a BZ2 archive. This command is run locally from the machine you want to backup.
First, create your file
Inside xf, paste the following:
dd if=/dev/vda1 of=/dev/stdout bs=1M | bzip2 | ssh firstname.lastname@example.org “cat – > /home/backups/Live.img.bz2”
Let’s break this down, so you can create your own command!
First, start by doing a [raw]df -a[/raw] to determine the name of your disk, replacing /dev/vda1 with the disk you want to backup.
Second, change email@example.com to your remote server. For best practices you should exchange SSH keys so there is no password prompt. See this tutorial here to exchange keys.
Finally, change /home/backups/Live.img.bz2 to the destination directory and filename you would like on the remote server.
Run the script in a shell to test, and finally automate.
Be sure to make your script executable by running [raw]chmod +x[/raw] after creation. To run in the background, install [raw]apt-get install nohup[/raw]. This will allow you to start your backup script in the background, allowing it plenty of time to execute. [raw]nohup ./scriptname &[/raw] will run the script as a daemon.