Skip to content

Instantly share code, notes, and snippets.

@jpylypiw
Last active February 1, 2020 00:38
Show Gist options
  • Save jpylypiw/d792c144e30d2a29f242f734f4158b8d to your computer and use it in GitHub Desktop.
Save jpylypiw/d792c144e30d2a29f242f734f4158b8d to your computer and use it in GitHub Desktop.
TeamSpeak3 Super Tiny Backup Script
#!/bin/bash
# add this to your crontab to execute a backup at 4am every day.
# note that the output will be written to /var/log/syslog so you can check if everything works fine.
# 0 4 * * * /bin/bash /opt/scripts/ts3backup.sh 2>&1 | logger -t ts3backup
BACKUPDIR="/opt/backup/ts3server"
TS3SERVERDIR="/home/ts3server/ts3server"
DATETIME=$(date +%Y-%m-%d_%H-%M)
BACKUPFILENAME="${DATETIME}_ts3server.tar.gz"
BACKUPMAXAGE="7"
mkdir -p ${BACKUPDIR}
if [ ! -d ${TS3SERVERDIR} ]; then
echo "TeamSpeak3 Server directory not found at:"
echo ${TS3SERVERDIR}
exit 1
fi
if tar -czf "${BACKUPDIR}/${BACKUPFILENAME}" ${TS3SERVERDIR}; then
echo "backup successfully created at ${BACKUPDIR}/${BACKUPFILENAME}"
else
echo "oh, we got a error when creating the file. check the output!"
exit 1
fi
if ! find ${BACKUPDIR} -type f -mtime +${BACKUPMAXAGE} -exec rm -vf {} \;; then
echo "oh, we got a error when deleting old backup files. check output!"
exit 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment