diff --git a/README.md b/README.md index 8f06f1789badf132261538630d45cd35d04498d1..085e1a04d6279bc05cde396c3890ffa546737561 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,7 @@ All nagios scripts are located under `nagios` directory. * Script for remove all logs from test accounts from SimpleSAMLlogs * Params: - * 1 - The file name \ No newline at end of file + * 1 - The file name + +### backup_database.sh +* Do mysqldump into `/opt/mariadb_backup` and remove all dump file older than 7 days \ No newline at end of file diff --git a/backup_database.sh b/backup_database.sh new file mode 100755 index 0000000000000000000000000000000000000000..ae9783428ba90da3c0fe09cc3ae20f8ed7a98f88 --- /dev/null +++ b/backup_database.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +BACKUP_FOLDER="/opt/mariadb_backup" + +# Ensure that backup folder exist +if [[ ! -d ${BACKUP_FOLDER} ]]; then + mkdir ${BACKUP_FOLDER} +fi + +BACKUP_FILE_NAME=${BACKUP_FOLDER}/backup_$(date -u +'%Y-%m-%d_%HH:%MM').sql + +# Backup all databases +mysqldump --all-databases > ${BACKUP_FILE_NAME} + +echo "Database was dumped into ${BACKUP_FILE_NAME}" + +#Remove old backups > 7days +find ${BACKUP_FOLDER} -name "backup_*.sql" -type f -mtime +7 -delete