Browse Source

Added cleanup functionality

Added the command line parameters --cleanup and -c an the variable
$KEEP.

We're now able to cleanup ol backup sets.
master
Christian Baer 7 years ago
parent
commit
5490cc3bb3
3 changed files with 16 additions and 3 deletions
  1. +3
    -1
      .gitignore
  2. +4
    -1
      rmbackup.d/sample.conf.dist
  3. +9
    -1
      rmbackup.sh

+ 3
- 1
.gitignore View File

@@ -1 +1,3 @@
.DS_Store
.DS_Store
*.sublime-*
.gitignore

+ 4
- 1
rmbackup.d/sample.conf.dist View File

@@ -18,4 +18,7 @@ TARGET="/Backups/"
# RSYNC_CONF=(-v)

# Uncomment and add your address if you want to receive the script ouput via e-mail
#MAILREC="jdoe@example.com"
#MAILREC="jdoe@example.com"

# How many backups should we keep (in days)
KEEP=14

+ 9
- 1
rmbackup.sh View File

@@ -43,12 +43,13 @@ LOG=$0.log

### Do not edit below this line ###


while [ $# -gt 0 ]; do # Until we tun out of parameters . . .
if [ $1 = "--backup-mysql" ] || [ $1 = "-m" ]; then
DOBACKUPMYSQL="true"
elif [ $1 = "--backup-files" ] || [ $1 = "-f" ]; then
DOBACKUPFILES="true"
elif [ $1 = "--cleanup" ] || [ $1 = "-c" ]; then
CLEANUP="true"
fi
shift # Check next set of parameters.
done
@@ -58,6 +59,7 @@ for f in $CONFLOCATION
do
# Set some defaults
SSH_PORT=22
KEEP=14

# load config file
source $f
@@ -73,6 +75,11 @@ do

TARGET=$TARGET$SSH_SERVER/

if [ "$CLEANUP" == "true" ]; then
find $TARGET -type d \( ! -iname "mysql" ! -iname "last" ! -iname ".*" \) -maxdepth 1 -mtime +$KEEP -exec rm -r '{}' '+'
find $TARGET/mysql/ -type d -maxdepth 1 -mtime +$KEEP -exec rm -r '{}' '+'
fi

if [ "$DOBACKUPFILES" == "true" ]; then

$ECHO $($DATE)" starting file backup for "$SSH_SERVER" (using config file"$f")" >> $LOG
@@ -146,6 +153,7 @@ do
unset hasMycnf
unset MAILREC
unset ERROR
unset KEEP

# send mail if it's configured
if [ -n "$MAILREC" ]; then


Loading…
Cancel
Save