Skip to content

Instantly share code, notes, and snippets.

@sdesalas
Created May 22, 2022 17:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdesalas/b16defd5f087b5da3dd68d78ac900367 to your computer and use it in GitHub Desktop.
Save sdesalas/b16defd5f087b5da3dd68d78ac900367 to your computer and use it in GitHub Desktop.
Db backup scripts
for DB in $(mysql -u root -p<password> -h <IP of DB> -e 'show databases' -s --skip-column-names); do
mysqldump -u root -p<password> -h<IP of DB> $DB > "$DB.sql";
@sdesalas
Copy link
Author

A quick script from any networked machine or even the host;

for DB in $(mysql -u root -p<password> -h <IP of DB> -e 'show databases' -s --skip-column-names); do
mysqldump -u root -p<password> -h<IP of DB> $DB > "$DB.sql";
done

Dumps out all the databases in the mysql/mariadb instance to individual .sql files. If you need to restore, just mysql -u root -p -h < file.sql

I have this running in a CRON job every four hours against my MariaDB Galera cluster. I periodically test restores on a test MariaDB or mysql instance by doing a restore and attempting queries.

@sdesalas
Copy link
Author

I like to mysqldump | gzip --rsyncable | restic --stdin

works great, deduplicated snapshot directly into a cloud bucket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment