Skip to content

Instantly share code, notes, and snippets.

@TaylorJadin
Last active December 18, 2023 04:52
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 TaylorJadin/d55161f79cbe7726cf04e1b1b3e9d24f to your computer and use it in GitHub Desktop.
Save TaylorJadin/d55161f79cbe7726cf04e1b1b3e9d24f to your computer and use it in GitHub Desktop.
backup script
#!/bin/bash
TARGET="/root/foundry"
DESTINATION="/root/backups"
BACKUPS_TO_KEEP=20
NOW=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
slow() {
start=`date +%s`
tar -cvJf "$DESTINATION/$NOW.tar.xz" $TARGET
end=`date +%s`
echo Backup took `expr $end - $start` seconds.
}
fast() {
start=`date +%s`
tar -cvzf "$DESTINATION/$NOW.tar.gz" $TARGET
end=`date +%s`
echo Backup took `expr $end - $start` seconds.
}
cleanup() {
N=$(($BACKUPS_TO_KEEP + 1))
(cd $DESTINATION && ls -tp | grep -v '/$' | tail -n +$N | xargs -I {} rm -- {})
}
### Main ###
if [ "$1" = "" ]; then
fast
cleanup
else
while [ "$1" != "" ]; do
case $1 in
-s | --slow ) shift
slow
;;
-f | --fast ) fast
;;
-c | --cleanup ) cleanup
;;
* ) echo "invalid flag: $1"
exit 1
esac
shift
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment