Skip to content

Instantly share code, notes, and snippets.

@frederickding
Last active December 20, 2015 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frederickding/6117125 to your computer and use it in GitHub Desktop.
Save frederickding/6117125 to your computer and use it in GitHub Desktop.
Backs up full filesystem to an xz-compressed tarball.
#!/bin/bash
XZ_OPT=-9
DATE=$(date +'%Y%m%d')
FILENAME="/"`hostname -f`"-$DATE.tar.xz"
printf "FULL FILESYSTEM BACKUP SCRIPT\n"
printf '==============================='
printf "\n"
printf "Current date: %s\n" "$DATE"
printf "Archive will be stored at: %s\n" "$FILENAME"
tar -cvpJf $FILENAME --exclude=$FILENAME \
--exclude=/var/swapfile \
--exclude=/dev/* \
--exclude=/media/* \
--exclude=/mnt/* \
--exclude=/proc/* \
--exclude=/sys/* \
--exclude=/tmp/* \
--exclude=/etc/fstab \
--exclude=/var/run/* \
--exclude=/var/lock/* \
--exclude=/lib/modules/*/volatile/.mounted \
--exclude=/var/cache/apt/archives/* \
--exclude=/usr/lib/jvm/* \
--one-file-system /
FILESIZE=$(stat -c %s $FILENAME 2>/dev/null)
if [[ $FILESIZE > 0 ]]; then
MD5SUM=$(md5sum $FILENAME)
SHA1SUM=$(sha1sum $FILENAME)
printf "Backup completed.\n"
du -h $FILENAME
printf "MD5 hash: %s\n" "$MD5SUM"
printf "SHA1 hash: %s\n" "$SHA1SUM"
else
printf "Backup may not have completed successfully.\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment