database_backup

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

commit d7136ee6a1040e82ff3af42cc21be0144605ef00
parent 0d0691f9a7759ddf23ab5ba719240fcf9005882d
Author: John Kubach <johnkubach@gmail.com>
Date:   Tue, 29 Jan 2019 22:13:09 -0500

add backup script

Diffstat:
AdatabaseBackup.sh | 30++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+), 0 deletions(-)

diff --git a/databaseBackup.sh b/databaseBackup.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# DATABASE BACKUP SCRIPT +# POPULATE THE FOLLOWING VARIABLES: +# DATABASELOCATION, BACKUPLOCATION + +DATE=$(date +%F.%T) + +# Location of database file(s) +DATABASELOCATION="" + +# Three different arguments may be specified. +# -d : daily backup +# -w : weekly backup +# -m : monthly backup +while getopts dwm option +do + case "${option}" + in + d) BACKUPLOCATION="/daily";; + w) BACKUPLOCATION="/weekly";; + m) BACKUPLOCATION="/monthly";; + esac +done + +rsync -rav $DATABASELOCATION $BACKUPLOCATION/$DATE + +# Only keep 2 backups +find $BACKUPLOCATION/* -type d | sort -r | sed -n '3,$p' | xargs rm -r + +# TODO: Check if there are more that 2 backups before attempting to remove