Zemedelphos

backup.sh

Nov 5th, 2015
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.00 KB | None | 0 0
  1. #!/bin/bash
  2. # Set these values to match your server's settings.
  3.  
  4. # This script should be located in the craftbukkit folder
  5.  
  6. # Make sure you change this to the name of your world folder!
  7. # Add additional worlds by separating them with a space.
  8.  
  9. declare -a worlds=(world)
  10. backupdir=backups/
  11. ext=.zip
  12.  
  13. hdateformat=$(date '+%Y-%m-%d-%H-%M-%S')H$ext
  14. ddateformat=$(date '+%Y-%m-%d')D$ext
  15. numworlds=${#worlds[@]}
  16.  
  17.     echo "Starting world backup..."
  18.  
  19.     if [ -d $backupdir ] ; then
  20.         sleep 0
  21.     else
  22.         mkdir -p $backupdir
  23.     fi
  24.     zip $backupdir$hdateformat -r plugins
  25.     for ((i=0;i<$numworlds;i++)); do
  26.         zip -q $backupdir$hdateformat -r ${worlds[$i]}
  27.         echo "Saving '${worlds[$i]}' to '$backupdir$hdateformat'."
  28.     done
  29.     cp $backupdir$hdateformat $backupdir$ddateformat
  30.     echo "Updated daily backup."
  31.     find $backupdir/ -name *H$ext -mmin +1440 -exec rm {} \;
  32.     find $backupdir/ -name *D$ext -mtime +14 -exec rm {} \;
  33.     echo "Removed old backups."
  34.  
  35.     echo "Backup complete."
  36.  
  37. exit 0
Advertisement
Add Comment
Please, Sign In to add comment