Skip to content

Instantly share code, notes, and snippets.

@luhaoming
Created December 25, 2017 06:38
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 luhaoming/0d033b12a7999308118e9081ddc6ac7c to your computer and use it in GitHub Desktop.
Save luhaoming/0d033b12a7999308118e9081ddc6ac7c to your computer and use it in GitHub Desktop.
full and diff backup with 7zip at linux
#!/bin/bash
# daily backup
# last update 2017-12-25
#
function usage {
echo "$1 not set"
echo "usage: "
echo "7zback <BackToPath> <BackfromPath>" && exit 1
}
DIRR=$1
BACK=$2
if [ -z $DIRR ]; then usage BackTo; fi
if [ -z $BACK ]; then usage Backfrom; fi
TODAY=$(date +"%Y%m%d%H%M")
MONTH=$(date +"%Y%m")
echo "Starting backup...." > log.
echo " "
# www backup
if [ ! -f $DIRR/back-$MONTH.7z ];
then
echo "www - creating monthly backup."
7za a $DIRR/back-$MONTH.7z "$BACK"
else
echo "www - creating nightly backup."
7za u $DIRR/back-$MONTH.7z "$BACK" -ms=off -t7z -u- -up0q3r2x2y2z0w2!$DIRR/back-$TODAY.7z
fi
echo
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment