Skip to content

Instantly share code, notes, and snippets.

@rushirajnenuji
Created September 2, 2020 18:35
Show Gist options
  • Save rushirajnenuji/3043324c8515b9f4729d5b86f47e9574 to your computer and use it in GitHub Desktop.
Save rushirajnenuji/3043324c8515b9f4729d5b86f47e9574 to your computer and use it in GitHub Desktop.
MySQL back up scripts
#! /bin/bash
PR=/apps/ezid/apps/apache/ezid/SITE/PROJECT
SF=$PR/settings/ezid.conf.shadow
BD=/apps/ezid/backups
DATE=$(date +%Y-%m-%d)
SBF=$BD/$DATE.store.txt.gz
MBF=$BD/$DATE.mysql.sql.gz
DB=rds-ias-ezid-search-prd.cmcguhglinoa.us-west-2.rds.amazonaws.com
keep=14
function mysqlpw {
local password=$(grep '^store_password: [^ ]' $SF)
if [ "$password" == "" ]; then
echo "ERROR: unable to locate database password"
return 1
fi
echo ${password#*: }
}
$PR/tools/dump-store -rz > $SBF
if [ $? -ne 0 ]; then
rm -f $SBF
echo "daily: dump-store failed" >&2
exit 1
fi
# Once a week, create a full MySQL dump.
if [ $(date +%u) -eq 7 ]; then
ignore=""
else
ignore="--ignore-table=ezid.ezidapp_storeidentifier"
ignore+=" --ignore-table=ezid.ezidapp_searchidentifier"
ignore+=" --ignore-table=ezid.ezidapp_linkchecker"
fi
mysqldump -h $DB -u ezidro --password="$(mysqlpw)"\
--opt --single-transaction --compress --hex-blob $ignore\
ezid | gzip > $MBF
if [ $? -ne 0 ]; then
rm -f $MBF
echo "daily: mysqldump failed" >&2
exit 1
fi
backups=($(ls $BD | grep '^[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\.store\.txt\.gz$'))
while [ ${#backups[@]} -gt $keep ]; do
rm $BD/${backups[0]}
rm -f $BD/${backups[0]/store.txt/mysql.sql}
backups=(${backups[@]:1})
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment