Infra_

MTA:SA Automatic Mapping Server Backups

Mar 30th, 2020
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.53 KB | None | 0 0
  1. #!bin/sh
  2. #title          :   backup.sh
  3. #description    :   This script will create a backup of MTA Server resource files
  4. #author         :   Daniel 'dnlk' Keller
  5. #version        :   1.1
  6. #notes          :   requires root access, zip (apt-get install zip), usage with cron recommended (apt-get install cron).
  7.  
  8. #                   cron usage:
  9. #                       m h dom mon dow
  10. #                       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
  11. #
  12. #                       add this line to /etc/crontab, adjust the path and you're done.
  13. #                       0 1 * * * root bash /path/to/backup.sh
  14.  
  15. BACKUP_DIR="/home/gameserver/.backups"
  16. SERVER_DIR=("/home/gameserver/mta-*")
  17. #   Alternatively you can use an array of directories for SERVER_DIR instead of a pattern
  18. #   e.g.
  19. #   SERVER_DIR=(
  20. #       /path/to/server1
  21. #       /completly/different/path/to/server2
  22. #       /oh/hey/here/is/server3
  23. #   )
  24.  
  25. IGNORED_DIRS=(
  26.     [admin]
  27.     [editor]
  28.     [gamemodes]
  29.     [gameplay]
  30.     [managers]
  31.     [web]
  32.     [tools]
  33.     [scripts]
  34.     editor_test
  35.     editor_dump
  36. )
  37.  
  38. find $BACKUP_DIR -type f -mtime +7 -exec rm {} \; # Find files older than 7 days and delete them.
  39.  
  40. for CURRENT_DIR in ${SERVER_DIR[@]}; do
  41.     CURRENT_DIR="$CURRENT_DIR/mods/deathmatch/resources"
  42.     BACKUP_DIRS=()
  43.     for MAP_DIR in $CURRENT_DIR/*; do
  44.         if [ -d "$MAP_DIR" ]; then
  45.             MAP_DIR=${MAP_DIR##*/}
  46.             [[ ! "${IGNORED_DIRS[*]}" == *"$MAP_DIR"* ]] && BACKUP_DIRS+=($MAP_DIR)
  47.         fi
  48.     done
  49.     zip -r $BACKUP_DIR/$(stat -c '%U' $CURRENT_DIR)-$(date '+%d.%m.%Y-%H:%M').zip -- ${BACKUP_DIRS[@]} > /dev/null 2>&1
  50. done
  51. exit
Advertisement
Add Comment
Please, Sign In to add comment