Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save carlosleonam/ddd59046a84331c9036458338cc87db5 to your computer and use it in GitHub Desktop.
Save carlosleonam/ddd59046a84331c9036458338cc87db5 to your computer and use it in GitHub Desktop.
7zip (7z) to Backup MySQL/MariaDB Databases

7zip (7z) to Backup MySQL/MariaDB Databases

Remenber to install &zip before

Create a simple shell script

#!/bin/bash

BACKUPDIR="/backup/databases/"
DATE=`date +%s`

if [ ! -e $BACKUPDIR ]; then
mkdir -p $BACKUPDIR
chmod 700 $BACKUPDIR
fi

for x in `mysqlshow -u $1 -p$2 | grep -v \_schema | awk -F "| " '{print $2}'`; do mysqldump -u $1 -p$2 $x | 7z a -si $BACKUPDIR$x-sql-$DATE.7z > nul ; done

# Uncomment below the line to keep only the last 3 backups (change if desired).
# /usr/bin/find $BACKUPDIR ! -mtime -3|/usr/bin/xargs rm -f

chmod 600 $BACKUPDIR/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment