Created
May 3, 2020 16:29
-
-
Save mhamzas/b39217253498f141d3c4cbf58d075ccb to your computer and use it in GitHub Desktop.
Backup Single Mysql/MariaDB with rclone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # To run this script you need to install https://rclone.org/ first | |
| # Use current date and time for future backup folder name | |
| TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S") | |
| # Declare the directory where the temporary backup files will be stored | |
| BACKUP_DIR="/backup/" | |
| # Declare the directory where the backup files will be stored in Remote | |
| BACKUP_DIR_REMOTE="/backup/" | |
| # State the username for your MySQL / MariaDB instace that can access the neccessary databases | |
| MYSQL_USER="" | |
| # Point this script to mysql executable file | |
| MYSQL=/usr/bin/mysql | |
| # State the password to the username above | |
| # Be aware that using plain password is unsecure | |
| MYSQL_PASSWORD="" | |
| # State the database name | |
| MYSQL_DB_NAME="" | |
| # Point this script to mysqldump executable file | |
| MYSQLDUMP=/usr/bin/mysqldump | |
| # Declare the name of the remote that will be used as a remote storage | |
| REMOTE="" | |
| # Echo the starting notice | |
| echo -e "===\nStarted working with the $MYSQL_DB_NAME." | |
| # Use mysqldump to create and actual backup of your database | |
| $MYSQLDUMP --user=$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DB_NAME | xz -9 > "$BACKUP_DIR/$MYSQL_DB_NAME-$TIMESTAMP.sql.xz" | |
| # Use rclone to upload files to the remote backup server | |
| rclone move $BACKUP_DIR $REMOTE:$BACKUP_DIR_REMOTE | |
| # Echo the result | |
| echo -e "===\nFinished backup process for $MYSQL_DB_NAME. Check your remote folder or watch for errors." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment