Add support for mysql databases
This commit is contained in:
parent
3782cdf528
commit
02140f07db
79
bare.sh
79
bare.sh
|
@ -93,7 +93,8 @@ function usage-repo() {
|
||||||
echo " restic Backup using restic (default repo is Backblaze B2 bucket \$B2_BUCKET_PREFIX-<reponame>)"
|
echo " restic Backup using restic (default repo is Backblaze B2 bucket \$B2_BUCKET_PREFIX-<reponame>)"
|
||||||
echo " rclone Backup using rclone (default repo is Backblaze B2 bucket \$B2_BUCKET_PREFIX-<reponame>)"
|
echo " rclone Backup using rclone (default repo is Backblaze B2 bucket \$B2_BUCKET_PREFIX-<reponame>)"
|
||||||
echo " rsync Backup using rsync (default repo is \$DEF_RSYNC_USER@\$DEF_RSYNC_SERVER:\$DEF_RSYNC_DIR/<reponame>)"
|
echo " rsync Backup using rsync (default repo is \$DEF_RSYNC_USER@\$DEF_RSYNC_SERVER:\$DEF_RSYNC_DIR/<reponame>)"
|
||||||
echo " postgres Dump all postgres databases. Instead of local file path, specify database name to backup. If empty, all dbs are backed up."
|
echo " postgres Dump postgres databases. Instead of local file path, specify database name to backup. If empty, all dbs are backed up."
|
||||||
|
echo " mysql Dump mysql databases. Instead of local file path, specify database name to backup. If empty, all dbs are backed up."
|
||||||
echo ""
|
echo ""
|
||||||
echo "Pre-backup commands to access local files:"
|
echo "Pre-backup commands to access local files:"
|
||||||
echo " nfs Mount \$DEF_NFS_SERVER:\$DEF_NFS_SERVER_BASE/<sharename> to <repopath>"
|
echo " nfs Mount \$DEF_NFS_SERVER:\$DEF_NFS_SERVER_BASE/<sharename> to <repopath>"
|
||||||
|
@ -362,9 +363,8 @@ function do_mount() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
# datapath is used for sql filename in pgsql/mysql backups
|
||||||
checktag "$f" postgres # datapath is used for sql filename in pgsql backups
|
if checktag "$f" postgres; then
|
||||||
if [[ $? -eq 0 ]]; then
|
|
||||||
# Make sure the db exists
|
# Make sure the db exists
|
||||||
if ! [[ -z ${DATAPATH} ]]; then
|
if ! [[ -z ${DATAPATH} ]]; then
|
||||||
psql -lqt | cut -d \| -f 1 | grep -qw ${DATAPATH}
|
psql -lqt | cut -d \| -f 1 | grep -qw ${DATAPATH}
|
||||||
|
@ -373,6 +373,15 @@ function do_mount() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
elif checktag "$f" mysql; then
|
||||||
|
# Make sure the db exists
|
||||||
|
if ! [[ -z ${DATAPATH} ]]; then
|
||||||
|
mysql -e 'show databases' | grep -v "^Database$" | grep -qw ${DATAPATH}
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
log "Error: MySQL database '${DATAPATH}' doesn't exist"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
if ! [[ -e ${DATAPATH} ]]; then
|
if ! [[ -e ${DATAPATH} ]]; then
|
||||||
log "Error: ${DATAPATH} doesn't exist"
|
log "Error: ${DATAPATH} doesn't exist"
|
||||||
|
@ -385,6 +394,7 @@ function do_mount() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -676,6 +686,8 @@ if [[ $CMD == "repos" ]]; then
|
||||||
|
|
||||||
if [[ $tags == *postgres* && -z $thispath ]]; then
|
if [[ $tags == *postgres* && -z $thispath ]]; then
|
||||||
thispath="(all dbs)"
|
thispath="(all dbs)"
|
||||||
|
elif [[ $tags == *mysql* && -z $thispath ]]; then
|
||||||
|
thispath="(all dbs)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
line=$(printf "$format" "$thisrepo" "$thispath" "$thisrpath" "$tags")
|
line=$(printf "$format" "$thisrepo" "$thispath" "$thisrpath" "$tags")
|
||||||
|
@ -754,7 +766,10 @@ for f in $REPO_LIST; do
|
||||||
|
|
||||||
if [[ -z $DATAPATH ]]; then
|
if [[ -z $DATAPATH ]]; then
|
||||||
checktag "$f" postgres
|
checktag "$f" postgres
|
||||||
if [[ $? -ne 0 ]]; then
|
pgrv=$?
|
||||||
|
checktag "$f" mysql
|
||||||
|
myrv=$?
|
||||||
|
if [[ $pgrv -ne 0 && $myrv -ne 0 ]]; then
|
||||||
log "error - can't find matching repo for $f - make sure it is listed in ${REPOFILE}"
|
log "error - can't find matching repo for $f - make sure it is listed in ${REPOFILE}"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
@ -899,6 +914,10 @@ for f in $REPO_LIST; do
|
||||||
if [[ $? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
CONNECTIONSOPTS="$OTHEROPTS --tag postgres"
|
CONNECTIONSOPTS="$OTHEROPTS --tag postgres"
|
||||||
fi
|
fi
|
||||||
|
checktag "$f" mysql
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
CONNECTIONSOPTS="$OTHEROPTS --tag mysql"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $VERBOSE -eq 1 ]]; then
|
if [[ $VERBOSE -eq 1 ]]; then
|
||||||
OTHEROPTS="$OTHEROPTS -v"
|
OTHEROPTS="$OTHEROPTS -v"
|
||||||
|
@ -919,6 +938,19 @@ for f in $REPO_LIST; do
|
||||||
DBOPTS="$DBOPTS ${DATAPATH}" # Last dbdump option is database name
|
DBOPTS="$DBOPTS ${DATAPATH}" # Last dbdump option is database name
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
checktag "$f" mysql
|
||||||
|
if [[ $? -eq 0 ]]; then
|
||||||
|
DBOPTS="$DBOPTS --all-databases --master-data --single-transaction"
|
||||||
|
OTHEROPTS="$OTHEROPTS --stdin"
|
||||||
|
if [[ -z ${DATAPATH} ]]; then
|
||||||
|
DBDUMPCMD="mysqldump"
|
||||||
|
DBFILENAME="mysql_alldbs.sql"
|
||||||
|
else
|
||||||
|
DBDUMPCMD="mysqldump"
|
||||||
|
DBFILENAME="mysql_${DATAPATH}.sql"
|
||||||
|
DBOPTS="$DBOPTS ${DATAPATH}" # Last dbdump option is database name
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
export RESTIC_EXCLUDEFILE=`getrepoexcludefile "$f"`
|
export RESTIC_EXCLUDEFILE=`getrepoexcludefile "$f"`
|
||||||
if [[ ! -z $RESTIC_EXCLUDEFILE ]]; then
|
if [[ ! -z $RESTIC_EXCLUDEFILE ]]; then
|
||||||
|
@ -1026,12 +1058,18 @@ for f in $REPO_LIST; do
|
||||||
fi
|
fi
|
||||||
elif [[ $mode == "restic" ]]; then
|
elif [[ $mode == "restic" ]]; then
|
||||||
if [[ $CMD == "go" ]]; then
|
if [[ $CMD == "go" ]]; then
|
||||||
|
if checktag "$f" postgres; then
|
||||||
|
btype=postgres
|
||||||
|
elif checktag "$f" mysql; then
|
||||||
|
btype=mysql
|
||||||
|
else
|
||||||
|
btype=normal
|
||||||
|
fi
|
||||||
if [[ $CRONMODE -eq 1 ]]; then
|
if [[ $CRONMODE -eq 1 ]]; then
|
||||||
if [[ $VERBOSE -eq 1 ]]; then
|
if [[ $VERBOSE -eq 1 ]]; then
|
||||||
echo "debug: running: [${RESTIC} backup $AUTHOPTS $CONNECTIONSOPTS $SPEEDOPTS $OTHEROPTS $DATAPATH" >>${LOG}
|
echo "debug: running: [${RESTIC} backup $AUTHOPTS $CONNECTIONSOPTS $SPEEDOPTS $OTHEROPTS $DATAPATH" >>${LOG}
|
||||||
echo "debug: full log is in ${FULLLOGFILE}" >>${LOG}
|
echo "debug: full log is in ${FULLLOGFILE}" >>${LOG}
|
||||||
checktag "$f" postgres
|
if [[ $btype == "postgres" || $btype == "mysql" ]] ; then
|
||||||
if [[ $? -eq 0 ]] ; then
|
|
||||||
$DBDUMPCMD $DBOPTS | ${RESTIC} backup $AUTHOPTS $CONNECTIONSOPTS $SPEEDOPTS $OTHEROPTS --stdin-filename $DBFILENAME 2>&1 >> ${FULLLOGFILE}
|
$DBDUMPCMD $DBOPTS | ${RESTIC} backup $AUTHOPTS $CONNECTIONSOPTS $SPEEDOPTS $OTHEROPTS --stdin-filename $DBFILENAME 2>&1 >> ${FULLLOGFILE}
|
||||||
rv=$?
|
rv=$?
|
||||||
else
|
else
|
||||||
|
@ -1040,18 +1078,16 @@ for f in $REPO_LIST; do
|
||||||
fi
|
fi
|
||||||
egrep "^(Added|processed|snapshot)" ${FULLLOGFILE} >>${LOG}
|
egrep "^(Added|processed|snapshot)" ${FULLLOGFILE} >>${LOG}
|
||||||
else
|
else
|
||||||
checktag "$f" postgres
|
if [[ $btype == "postgres" || $btype == "mysql" ]] ; then
|
||||||
if [[ $? -eq 0 ]] ; then
|
$DBDUMPCMD $DBOPTS | ${RESTIC} backup $AUTHOPTS $CONNECTIONSOPTS $SPEEDOPTS $OTHEROPTS --stdin-filename $DBFILENAME 2>&1 | egrep "^(Added|processed|snapshot)" >> ${LOG}
|
||||||
${RESTIC} backup $AUTHOPTS $CONNECTIONSOPTS $SPEEDOPTS $OTHEROPTS $DATAPATH 2>&1 | egrep "^(Added|processed|snapshot)" >> ${LOG}
|
|
||||||
rv=${PIPESTATUS[0]}
|
rv=${PIPESTATUS[0]}
|
||||||
else
|
else
|
||||||
$DBDUMPCMD $DBOPTS | ${RESTIC} backup $AUTHOPTS $CONNECTIONSOPTS $SPEEDOPTS $OTHEROPTS --stdin-filename $DBFILENAME 2>&1 | egrep "^(Added|processed|snapshot)" >> ${LOG}
|
${RESTIC} backup $AUTHOPTS $CONNECTIONSOPTS $SPEEDOPTS $OTHEROPTS $DATAPATH 2>&1 | egrep "^(Added|processed|snapshot)" >> ${LOG}
|
||||||
rv=${PIPESTATUS[0]}
|
rv=${PIPESTATUS[0]}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
checktag "$f" postgres
|
if [[ $btype == "postgres" || $btype == "mysql" ]] ; then
|
||||||
if [[ $? -eq 0 ]] ; then
|
|
||||||
[[ $VERBOSE -eq 1 ]] && log "debug: running: [$DBDUMPCMD $DBOPTS | ${RESTIC} backup $AUTHOPTS $CONNECTIONSOPTS $SPEEDOPTS $OTHEROPTS --stdin-filename $DBFILENAME"
|
[[ $VERBOSE -eq 1 ]] && log "debug: running: [$DBDUMPCMD $DBOPTS | ${RESTIC} backup $AUTHOPTS $CONNECTIONSOPTS $SPEEDOPTS $OTHEROPTS --stdin-filename $DBFILENAME"
|
||||||
$DBDUMPCMD $DBOPTS | ${RESTIC} backup $AUTHOPTS $CONNECTIONSOPTS $SPEEDOPTS $OTHEROPTS --stdin-filename $DBFILENAME 2>&1 >> ${LOG}
|
$DBDUMPCMD $DBOPTS | ${RESTIC} backup $AUTHOPTS $CONNECTIONSOPTS $SPEEDOPTS $OTHEROPTS --stdin-filename $DBFILENAME 2>&1 >> ${LOG}
|
||||||
rv=$?
|
rv=$?
|
||||||
|
@ -1064,9 +1100,10 @@ for f in $REPO_LIST; do
|
||||||
elif [[ $CMD == "get" ]]; then
|
elif [[ $CMD == "get" ]]; then
|
||||||
RESTOREDIR="$RESTOREDIRBASE/$f/"
|
RESTOREDIR="$RESTOREDIRBASE/$f/"
|
||||||
snaps=$(${RESTIC} snapshots $AUTHOPTS $CONNECTIONSOPTS 2>&1 | grep -v ID | awk '(NF >= 4) { print }')
|
snaps=$(${RESTIC} snapshots $AUTHOPTS $CONNECTIONSOPTS 2>&1 | grep -v ID | awk '(NF >= 4) { print }')
|
||||||
checktag "$f" postgres
|
if checktag "$f" postgres; then
|
||||||
if [[ $? -ne 0 ]]; then
|
|
||||||
snaps=$(echo "$snaps" | grep -v postgres)
|
snaps=$(echo "$snaps" | grep -v postgres)
|
||||||
|
elif checktag "$f" mysql; then
|
||||||
|
snaps=$(echo "$snaps" | grep -v mysql)
|
||||||
fi
|
fi
|
||||||
snapids=$(echo "$snaps" | awk '{ print $1 }')
|
snapids=$(echo "$snaps" | awk '{ print $1 }')
|
||||||
defsid=$(echo "$snapids" | tail -1)
|
defsid=$(echo "$snapids" | tail -1)
|
||||||
|
@ -1294,10 +1331,12 @@ for f in $REPO_LIST; do
|
||||||
fi
|
fi
|
||||||
elif [[ $mode == "rsync" ]]; then
|
elif [[ $mode == "rsync" ]]; then
|
||||||
REMOTE=""
|
REMOTE=""
|
||||||
checktag "$f" postgres
|
if checktag "$f" postgres; then
|
||||||
if [[ $? -eq 0 ]] ; then
|
|
||||||
log "Error: postgres backups not supported for rsync mode."
|
log "Error: postgres backups not supported for rsync mode."
|
||||||
rv=1
|
rv=1
|
||||||
|
elif checktag "$f" mysql; then
|
||||||
|
log "Error: mysql backups not supported for rsync mode."
|
||||||
|
rv=1
|
||||||
elif [[ $CMD == "go" ]]; then
|
elif [[ $CMD == "go" ]]; then
|
||||||
${RSYNC} ${RSYNC_OPTIONS} $DATAPATH/ ${RSYNC_REPOSITORY} 2>&1 >> ${LOG}
|
${RSYNC} ${RSYNC_OPTIONS} $DATAPATH/ ${RSYNC_REPOSITORY} 2>&1 >> ${LOG}
|
||||||
rv=$?
|
rv=$?
|
||||||
|
@ -1334,10 +1373,12 @@ for f in $REPO_LIST; do
|
||||||
else
|
else
|
||||||
# rclone
|
# rclone
|
||||||
REMOTE=""
|
REMOTE=""
|
||||||
checktag "$f" postgres
|
if checktag "$f" postgres; then
|
||||||
if [[ $? -eq 0 ]] ; then
|
|
||||||
log "Error: postgres backups not supported for $mode mode."
|
log "Error: postgres backups not supported for $mode mode."
|
||||||
rv=1
|
rv=1
|
||||||
|
elif checktag "$f" mysql; then
|
||||||
|
log "Error: mysql backups not supported for $mode mode."
|
||||||
|
rv=1
|
||||||
elif [[ $CMD == "go" ]]; then
|
elif [[ $CMD == "go" ]]; then
|
||||||
${RCLONE} sync $RCLONEOPTS $CONNECTIONSOPTS $SPEEDOPTS $OTHEROPTS $DATAPATH $RCLONE_REPOSITORY 2>&1 >> ${LOG}
|
${RCLONE} sync $RCLONEOPTS $CONNECTIONSOPTS $SPEEDOPTS $OTHEROPTS $DATAPATH $RCLONE_REPOSITORY 2>&1 >> ${LOG}
|
||||||
rv=$?
|
rv=$?
|
||||||
|
|
Loading…
Reference in New Issue