Partition backup is useful in many cases, especially when you want backup a fresh and configured operating system. In this case, if it is necessary to reinstall the system, you just have to restore the backup and everything becomes as it was in the beginning.
What we are going to do is an exact copy of the device of the partition. To save space, compression is a good option.
For compression be more effective, you should “clean” the free space. Mount the filesystem and run the next command inside of it:
dd if=/dev/zero of=zeros.bin bs=64k
This command will fill the empty zeros, reducing the compression to almost nothing. Before, you can remove temporary files to save even more space.
Then, unmount the filesystem. To create and restore the backup, issue the commands (replace
sda1 by your device):
sudo dd if=/dev/sda1 bs=64k | gzip -9 > backup_compressed.gz
gunzip -dc backup_compressed.gz | sudo dd of=/dev/sda1 bs=64k
It is useful to create a backup of a system and store it in another one for security reasons. We are going to mount the filesystem trough SSH and create
tar of it.
Start by installing:
sudo apt-get install sshfs
Mount filesystem trough SSH:
sudo sshfs firstname.lastname@example.org:/ /mnt/
If you are using SSH keys:
sudo sshfs -o IdentityFile=~/.ssh/id_rsa email@example.com:/ /mnt/
Then, create the backup:
sudo tar zcvf backup.tar.gz /mnt/
When finished, you can unmoun:
sudo umount /mnt