Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!bin/sh
- #title : backup.sh
- #description : This script will create a backup of MTA Server resource files
- #author : Daniel 'dnlk' Keller
- #version : 1.1
- #notes : requires root access, zip (apt-get install zip), usage with cron recommended (apt-get install cron).
- # cron usage:
- # m h dom mon dow
- # 0 1 * * * will run this script at minute 0, hour 1 on every day of the month, in every month and at every day of the week. Basically every day at 1am
- #
- # add this line to /etc/crontab, adjust the path and you're done.
- # 0 1 * * * root bash /path/to/backup.sh
- BACKUP_DIR="/home/gameserver/.backups"
- SERVER_DIR=("/home/gameserver/mta-*")
- # Alternatively you can use an array of directories for SERVER_DIR instead of a pattern
- # e.g.
- # SERVER_DIR=(
- # /path/to/server1
- # /completly/different/path/to/server2
- # /oh/hey/here/is/server3
- # )
- IGNORED_DIRS=(
- [admin]
- [editor]
- [gamemodes]
- [gameplay]
- [managers]
- [web]
- [tools]
- [scripts]
- editor_test
- editor_dump
- )
- find $BACKUP_DIR -type f -mtime +7 -exec rm {} \; # Find files older than 7 days and delete them.
- for CURRENT_DIR in ${SERVER_DIR[@]}; do
- CURRENT_DIR="$CURRENT_DIR/mods/deathmatch/resources"
- BACKUP_DIRS=()
- for MAP_DIR in $CURRENT_DIR/*; do
- if [ -d "$MAP_DIR" ]; then
- MAP_DIR=${MAP_DIR##*/}
- [[ ! "${IGNORED_DIRS[*]}" == *"$MAP_DIR"* ]] && BACKUP_DIRS+=($MAP_DIR)
- fi
- done
- zip -r $BACKUP_DIR/$(stat -c '%U' $CURRENT_DIR)-$(date '+%d.%m.%Y-%H:%M').zip -- ${BACKUP_DIRS[@]} > /dev/null 2>&1
- done
- exit
Advertisement
Add Comment
Please, Sign In to add comment