I would like to share the second version (1.1) of the Bash script backup_images-1.1.sh which you can use for cloning disks of remote Linux machines. The script reads IP addresses of the hosts from a file and copy the disks with dd command over SSH connection. The disks are stored on a local machine, compressed by gzip utility. Unlike the version 1.0, a new version brings these improvements:
- no root account is used for SSH connection and dd command; we rely solely on sudo password
- no modification of sudoers file is done
- SSH credentials and name of a disk are not longer required as script arguments; instead user is prompted for them
The sudo password is provided by the user during the script execution. Therefore, no sensitive information is visible in the process list and cannot be read from Bash history.
Picture 1 - Copying disk /dev/sda from hosts 192.168.1.33 and 192.168.1.34
Note: In case, there is more that one physical disk available (e.g. /dev/sda and /dev/sdb) and you copy only the disk where root partition is located (e.g. /dev/sda), your new VM boots into emergency mode. In that case you must boot your VM into single-user mode and remove disk /dev/sdb from /etc/fstab.
End.