Closed Bug 841035 Opened 12 years ago Closed 12 years ago

Add a cleanup option to base_backup.sh for cleaning up old Postgres base backups

Categories

(Data & BI Services Team :: DB: MySQL, task)

x86_64
Linux
task
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: selenamarie, Assigned: selenamarie)

Details

Adding a delete_old() routine to clean up old backups.
Done and pushed selena@wuzetian:~/repos/trunk/modules/postgres2/files/scripts$ svn diff Index: base_backup.sh =================================================================== --- base_backup.sh (revision 57803) +++ base_backup.sh (working copy) @@ -12,6 +12,7 @@ VERSION=9.2 STARTUP=0 COPYCONFIG=0 +KEEPBACKUPS=6 while getopts "h?c:sv:y" opt; do case "$opt" in @@ -44,8 +45,9 @@ CONFDIR="$REPLICADIR/conf" for i in STOPREP BASEBACKUP CLUSTER VERSION \ - PSQL PGCTL SOURCE SOURCEDIR \ - REPLICADIR PGRESTOREPORT TARGETDIR CONFDIR STARTUP COPYCONFIG ; do + PSQL PGCTL SOURCE SOURCEDIR KEEPBACKUPS \ + REPLICADIR PGRESTOREPORT TARGETDIR CONFDIR \ + REPLICABASEDIR STARTUP COPYCONFIG ; do if [ "${!i}" = '' ]; then echo "FATAL: Did not define $i"; exit 1 fi @@ -70,6 +72,31 @@ fi } + +delete_old() { + + # Safety to prevent accidentally wiping out all the backups + if [ 5 -gt "$KEEPBACKUPS" ]; then + echo "Warning! KEEPBACKUPS is set to less than five. Exiting." + exit 1 + fi + ## Have a look at $REPLICABASEDIR and get a list of the base backup dirs + num_backups=`ls $REPLICABASEDIR | wc -l` + + if [ "$num_backups" -gt "$KEEPBACKUPS" ]; then + ## Keep $KEEPBACKUP days of backups, remove anything more + let num_to_remove=num_backups-KEEPBACKUPS + remove_list=`ls -1 -tr $REPLICABASEDIR | head -${num_to_remove}` + echo $remove_list + for i in $remove_list; do + rm -rf $REPLICABASEDIR/$i + done + else + echo "Nothing to remove! Only $num_backups backups present." + fi + +} + echo "# Make a backup!" date @@ -119,8 +146,16 @@ fi fi -echo "# Done!" +echo "# Done with backup!" date +# Clean up + +echo "# Cleaning up old backup directories" +delete_old + +echo "# Done!" +date + exit 0 Index: backup_variables.sh.dist =================================================================== --- backup_variables.sh.dist (revision 57803) +++ backup_variables.sh.dist (working copy) @@ -11,8 +11,10 @@ SOURCEDIR=/pgdata/$VERSION CLUSTER=data REPLICADIR=/data/pgbasebackups/$VERSION/$TARGETDATE +REPLICABASEDIR=/data/pgbasebackups/$VERSION PGRESTOREPORT=7000 STOPREP=0 STARTUP=0 COPYCONFIG=0 +KEEPBACKUPS=6 selena@wuzetian:~/repos/trunk/modules/postgres2/files/scripts$ svn status M base_backup.sh M backup_variables.sh.dist selena@wuzetian:~/repos/trunk/modules/postgres2/files/scripts$ svn commit -m "Adding cleanup routine to postgres2 base_backup.sh script" Sending scripts/backup_variables.sh.dist Sending scripts/base_backup.sh Transmitting file data .. Committed revision 58480.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Product: mozilla.org → Data & BI Services Team
You need to log in before you can comment on or make changes to this bug.