Last active
December 20, 2015 10:39
-
-
Save frederickding/6117125 to your computer and use it in GitHub Desktop.
Backs up full filesystem to an xz-compressed tarball.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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