Backup linux for experts - lightblueseas/linuxstuff GitHub Wiki
If you hard-disk where Ubuntu is installed isn't too big, you can try booting from a live cd (any linux distro will do) and running:
dd if=/dev/sda of=/path/to/external/hardisk/mybackupfile
This makes a backup of your whole hard-disk, not just Ubuntu, and it'll also do all the empty bytes, but it's the only solution I can think of. To restore the backup, use:
dd if=/path/to/external/harddisk/mybackupfile of=/dev/sda
Solution took from askubuntu.com
Monitor dd
You can monitor the dd operations by installing the pipe viewer
sudo apt-get install pv
There after you can run dd as follows:
dd if=/dev/sda | pv | dd of=/path/to/external/hardisk/mybackupfile
5,63MB 0:00:05 [ 124kB/s] [ <=> ]
Examples
I have an old device here that i want to backup for restore later to my new device. So i have to copy my old m2-drive with the name:'/dev/nvme0n1p5' to an external usb-drive with path: '/media/astrapi69/backups/csl2/nvme0n1p5.img'. Here is the output:
dd if=/dev/nvme0n1p5 of=/media/astrapi69/backups/csl2/nvme0n1p5.img
dd: konnte '/dev/nvme0n1p5' nicht öffnen: Keine Berechtigung
➜ ~ sudo dd if=/dev/nvme0n1p5 of=/media/astrapi69/backups/csl2/nvme0n1p5.img
[sudo] Passwort für astrapi69:
718123008+0 Datensätze ein
718123008+0 Datensätze aus
367678980096 Bytes (368 GB, 342 GiB) kopiert, 1685,36 s, 218 MB/s
The first attempt did not have sudo permission so it is failed(output is in german language), but the second command succeded and copied my m2-drive in 30 minutes.
I dit not use the pipe viewer for the backup process but will use it for demonstration purposes in the restorement process.
Now we play the just created image to the new device with the following commands:
➜ ~ sudo dd if=/media/astrapi69/backups/csl2/nvme0n1p5.img | pv |sudo dd of=/dev/sda1
718123008+0 Datensätze ein] [ <=> ]
718123008+0 Datensätze aus
367678980096 Bytes (368 GB, 342 GiB) kopiert, 9662,28 s, 38,1 MB/s
342GiB 2:41:02 [36,3MiB/s] [ <=> ]
718123008+0 Datensätze ein
718123008+0 Datensätze aus
367678980096 Bytes (368 GB, 342 GiB) kopiert, 9664,15 s, 38,0 MB/s
cheatsheet
If your old device is bigger than you new device you have to shrink it. In my exampe i had an old device(that was 1000gb big but the pragmatic use was only 253gb) that was bigger that the my new device so i had to shrinked it to 350gb for fitting to the new device(480gb). I made this with gparted on a debian live cd, i think this is the best practice to do this process.