Skip to content

Instantly share code, notes, and snippets.

@greyltc
Last active September 1, 2019 20:22
Show Gist options
  • Select an option

  • Save greyltc/1b30af609d5857de07e4cde2d5c454fd to your computer and use it in GitHub Desktop.

Select an option

Save greyltc/1b30af609d5857de07e4cde2d5c454fd to your computer and use it in GitHub Desktop.
solar sim vm backup script
#!/usr/bin/env bash
echo ""
echo "=====Before backing up, ensure the following====="
echo "1: All removable drives are unmounted from the VM"
echo "2: All VM snapshots are gone (rolled into the base disk image)"
echo "3: The VM has been properly shut down"
echo "4: VirtualBox is not running"
echo ""
VM_FOLDER="/home/vm/VirtualBox VMs"
BACKUP_OUTPUT_FOLDER="/mnt/scratch/vbox_backup/"
TODAY="$(date -I)"
BACKUP_FILE_NAME="${TODAY}_solar_sim_virtualbox_backup.tar.xz"
BACKUP_FILE_FULLPATH="${BACKUP_OUTPUT_FOLDER}/${BACKUP_FILE_NAME}"
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
echo "Not running as root"
exit
fi
mkdir -p "${BACKUP_OUTPUT_FOLDER}"
echo "Now backing up ${VM_FOLDER}..."
XZ_DEFAULTS="--threads=0" tar --preserve-permissions --xattrs --acls -cJf "${BACKUP_FILE_FULLPATH}" "${VM_FOLDER}"
echo "Backup of ${VM_FOLDER} completed to ${BACKUP_FILE_FULLPATH}"
# and then to restore this properly: tar --acls -xpf backup_file.tar.xz
echo ""
echo "Calculating MD5 checksum..."
cd ${BACKUP_OUTPUT_FOLDER}
md5sum "${BACKUP_FILE_NAME}" > "${BACKUP_FILE_NAME}.md5"
cat "${BACKUP_FILE_NAME}.md5"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment