Changeset 52
- Timestamp:
- Jun 9, 2014, 11:58:45 AM (11 years ago)
- Location:
- scripts
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
scripts/etc/7dtd.conf
r35 r52 8 8 export SDTD_BASE=/home/sdtd 9 9 10 # Root directory for backups10 # Backup options 11 11 export SDTD_BACKUP_ROOT=/home/sdtd/backup 12 export SDTD_BACKUP_MIN_BACKUPS_KEEP= 13 export SDTD_BACKUP_MAX_BACKUPS= 14 export SDTD_BACKUP_MAX_STORAGE= 15 export SDTD_BACKUP_MAX_AGE= 16 export SDTD_BACKUP_COMPRESS=none 12 17 13 18 # User account and group to run the server -
scripts/usr/local/lib/7dtd/VERSION
r50 r52 1 Version: 1 32 Release: 2014-06-0 51 Version: 14 2 Release: 2014-06-09 -
scripts/usr/local/lib/7dtd/commands/backup.sh
r26 r52 4 4 5 5 sdtdCommandBackup() { 6 DT=`date "+%Y-%m-%d_%H-%M"`7 NewBackup=$SDTD_BACKUP_ROOT/$DT6 local DT=`date "+%Y-%m-%d_%H-%M"` 7 local NewBackup=$SDTD_BACKUP_ROOT/$DT 8 8 9 9 # Check for backup folder existence … … 11 11 # Exists, copy(link) latest backup 12 12 unset -v LatestBackup 13 for file in "$SDTD_BACKUP_ROOT"/*; do 14 [[ $file -nt $LatestBackup ]] && LatestBackup=$file 13 local fileI 14 for fileI in "$SDTD_BACKUP_ROOT"/*; do 15 if [ $fileI -nt $LatestBackup -a -d $fileI ]; then 16 LatestBackup=$fileI 17 fi 15 18 done 16 cp -al $LatestBackup $NewBackup 17 else 19 if [ -d $LatestBackup ]; then 20 cp -al $LatestBackup $NewBackup 21 fi 22 fi 23 24 if [ ! -d $SDTD_BACKUP_ROOT ]; then 18 25 # Create new backup dir 19 26 mkdir $SDTD_BACKUP_ROOT … … 22 29 $RSYNC -a --delete --numeric-ids --delete-excluded $SDTD_BASE/instances/./ $NewBackup 23 30 touch $NewBackup 31 32 ## Compress if enabled 33 case ${SDTD_BACKUP_COMPRESS:-none} in 34 all) 35 local dfname=$(basename $NewBackup) 36 cd $SDTD_BACKUP_ROOT 37 tar -czf $dfname.tar.gz $dfname 38 touch -r $dfname $dfname.tar.gz 39 rm -Rf $dfname 40 ;; 41 old) 42 if [ -d $LatestBackup ]; then 43 local dfname=$(basename $LatestBackup) 44 cd $SDTD_BACKUP_ROOT 45 tar -czf $dfname.tar.gz $dfname 46 touch -r $dfname $dfname.tar.gz 47 rm -Rf $dfname 48 fi 49 ;; 50 none) 51 ;; 52 esac 53 54 ## Purge old/too many backups 55 local keepMin=${SDTD_BACKUP_MIN_BACKUPS_KEEP:-0} 56 if [ $(isANumber $SDTD_BACKUP_MAX_BACKUPS) -eq 1 ]; then 57 local removeBut=$SDTD_BACKUP_MAX_BACKUPS 58 if [ $SDTD_BACKUP_MAX_BACKUPS -lt $keepMin ]; then 59 removeBut=$keepMin 60 fi 61 local num=0 62 local F 63 for F in $(ls -t1 $SDTD_BACKUP_ROOT); do 64 (( num++ )) 65 if [ $num -gt $removeBut ]; then 66 rm $F 67 fi 68 done 69 fi 70 if [ $(isANumber $SDTD_BACKUP_MAX_AGE) -eq 1 ]; then 71 local FINDBASE="find $SDTD_BACKUP_ROOT -mindepth 1 -maxdepth 1" 72 # Only continue if there are more than MIN_BACKUPS_KEEP backups at all 73 if [ $($FINDBASE | wc -l) -gt $keepMin ]; then 74 local minutes=$(( $SDTD_BACKUP_MAX_AGE*60 )) 75 while [ $($FINDBASE -mmin -$minutes | wc -l) -lt $keepMin ]; do 76 minutes=$(( minutes+60 )) 77 done 78 $FINDBASE -mmin +$minutes -exec rm -Rf {} \; 79 fi 80 fi 81 if [ $(isANumber $SDTD_BACKUP_MAX_STORAGE) -eq 1 ]; then 82 local maxKBytes=$(( $SDTD_BACKUP_MAX_STORAGE*1024 )) 83 local curNumFiles=$(ls -t1 $SDTD_BACKUP_ROOT | wc -l) 84 while [ $(du -sk $SDTD_BACKUP_ROOT) -gt $maxKBytes -a $curNumFiles -gt $keepMin ]; do 85 local toDel=$(ls -tr1 | head -n 1) 86 rm -Rf $toDel 87 (( curNumFiles-- )) 88 done 89 fi 24 90 25 91 for H in $(getHooksFor backup); do 26 92 $H $NewBackup 27 93 done 28 29 #echo "Backup folder disk usage: `$DU -sh $SDTD_BACKUP_ROOT`"30 94 } 31 95
Note:
See TracChangeset
for help on using the changeset viewer.