Backup and restore Linux server
1) Save backup
if you have enough free space on the server you can backup your server locally to /home/backup:
mkdir -p /home/backup
tar -cvpzf /home/backup/backup.tar.gz \
If you have other directories that you want to exclude from the backup, you can add more excludes.
If you don't have enough free space on the server, you can save the backup to the remote server via ssh:
tar -cvpzf - \
--exclude="/var/cache/apt/archives/*.deb" / | ssh -t [email protected] "cat > backup.tar.gz"
2) Restore backup
Run any livecd, for example systemrescuecd and create swap root and home partitions via fdisk or parted. I recommend to create at least swap root home and var but you may want to create swap and root only - whatever...
We assume that the swap is /dev/sda1 and the root is /dev/sda2 - let's make fs on partitions:
mkswap -L SWAP /dev/sda1
mkfs.ext4 -L ROOT /dev/sda2
Mount it to /tmp/target:
mount -t ext4 /dev/sda2 /tmp/target
Mount dev, proc, sys:
mount --bind /dev /tmp/target/dev
mount --bind /proc /tmp/target/proc
mount --bind /sys /tmp/target/sys
Chroot to /tmp/target:
Modify /etc/fstab to suit your partitions. It can be LABEL or UUID or /dev/* - run blkid and check it out.
update-initramfs -uk all
Exit chroot and reboot:
exit (or Ctrl+D)
If there are no errors, the new server will boot :)
This method is suitable for most distributions, Debian, Ubuntu, etc. For RedHat based or if you use LVM this method requires specific changes.
There are other ways, for example dd, but that's another story.