database_backup

Senior Project - Sprint 2019
Log | Files | Refs | README

databaseBackup.sh (674B)


      1 #!/bin/bash
      2 # DATABASE BACKUP SCRIPT
      3 # POPULATE THE FOLLOWING VARIABLES:
      4 #   WORKINGDIR, BACKUPLOCATION
      5 
      6 DATE=$(date +%F.%T)
      7 
      8 WORKINGDIR="/home/ec2-user/db_backups"
      9 cd $WORKINGDIR
     10 
     11 # Three different arguments may be specified.
     12 # -d : daily backup
     13 # -w : weekly backup
     14 # -m : monthly backup
     15 while getopts dwm option
     16 do
     17     case "${option}"
     18         in
     19         d) BACKUPLOCATION="daily";;
     20         w) BACKUPLOCATION="weekly";;
     21         m) BACKUPLOCATION="monthly";;
     22     esac
     23 done
     24 
     25 # rsync -rav $DATABASELOCATION $BACKUPLOCATION/$DATE
     26 mysqldump --all-databases > $BACKUPLOCATION/$DATE.sql
     27 
     28 # Only keep 2 backups
     29 find $BACKUPLOCATION/* -type f | sort -r | sed -n '3,$p' | xargs rm