Step 1 – Preparation of your server #
You will need some way to boot your server into a rescue mode, the hard disk you want to back up cannot be active while this happens, in most cases, you can boot your server into our rescue system if that is not available to you because you have a private VLAN or for some other reason you will be able to boot your server into rescue using a sysrescuecd ISO image via the servers IPMI we also have a guide to that here
Step 2 – Copy the disk image #
Once you have logged into the rescue system you can run the command: lsblk
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 8.2T 0 disk
├─sda1 8:1 0 2M 0 part
├─sda2 8:2 0 119.2G 0 part [SWAP]
├─sda3 8:3 0 93.1G 0 part /
└─sda4 8:4 0 8T 0 part
At the top level, you should see your disk name, in the above example it is /dev/sda, it could also be /dev/vda if it is a virtual machine or /dev/nvme0n1 if it is a virtual disk.
Once you have identified the correct disk to backup you can now make the image file.
Method 1 – Copy to another disk #
Source: /dev/sda
Destination: /backups directory on /dev/sdb2
Make a mount point for /dev/sdb2 which contains the /backup directory then mount the partition and dd and compress the /dev/sda disk image
mkdir /mnt/mybackup
mount /dev/sdb2 /mnt/mybackup
dd bs=32M if=/dev/sda status=progress | gzip > /mnt/mybackup/backup/sda-backup-file.gz
If you ever need to restore this you would do the following assuming the same system a few days later:
mkdir /mnt/mybackup
mount /dev/sdb2 /mnt/mybackup
gunzip -c /mnt/mybackup/backup/sda-backup-file.gz | dd bs=32M of=/dev/sda status=progress
That will then restore your backup file to the disk /dev/sda.
Method 2 – Copy the disk image over ssh to another server #
Source: /dev/sda
Destination: A server with the IP 20.30.40.50 into the /backup directory
We will copy the disk image over ssh using gzip to compress the 0’s (empty space)
dd bs=32M if=/dev/sda status=progress | gzip -9 | ssh root@20.30.40.50 "dd of=/backup/sda-backup-file.gz"
You will be prompted for your root user password then it will start.
To restore your remote disk image backup to the same source server a few days later for example you would run the following on the remote backup server:
gunzip -c /backup/sda-backup-file.gz | ssh root@original-source-server-ip "dd bs=32M of=/dev/sda"
You will not be able to get progress on this restore