Created
April 6, 2023 21:07
-
-
Save tkachev-o/e0d2376db67ca2cd4bbcda676f2507e8 to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
# $ crontab -u admin -e | |
# 3 05 * * * /home/admin/docker/backup-docker-db.sh or | |
# 3 05 * * * /home/admin/docker/backup-docker-db.sh >> /home/admin/docker/backup/backup.log 2>&1 | |
# Get current time | |
start_time=$(date '+%s') | |
BACKUP_FILE_NAME="tantra_db.$(date +"%Y-%m-%d_%H-%M-%S.sql.gz")" | |
BACKUP_DIR="/home/admin/docker/backup" | |
echo -e "$(date "+%F %T") -- DOCKER--" "$BACKUP_FILE_NAME" | tee -a $BACKUP_DIR/backup.log | |
/usr/bin/docker exec percona sh -c 'exec mysqldump -uroot -p"$MYSQL_ROOT_PASSWORD" --databases tantra_db' | gzip > "$BACKUP_DIR"/"$BACKUP_FILE_NAME"; | |
# Get current time | |
end_time=$(date '+%s') | |
# Calculation run time | |
run_time=$((end_time - start_time)) | |
run_time=$((run_time / 60)) | |
current_time=$(date "+%T") | |
if [ "$run_time" -lt 1 ]; then | |
run_time=1 | |
fi | |
min=minutes | |
if [ "$run_time" -eq 1 ]; then | |
min=minute | |
fi | |
echo "$(date "+%F %T") Runtime: $run_time $min" | tee -a $BACKUP_DIR/backup.log |
This file contains 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
2023-04-06 23:48:01 -- DOCKER-- tantra_db.2023-04-06_23-48-01.sql.gz | |
2023-04-06 23:48:07 Runtime: 1 minute | |
2023-04-06 23:53:01 -- DOCKER-- tantra_db.2023-04-06_23-53-01.sql.gz | |
2023-04-06 23:53:08 Runtime: 1 minute |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment