From c92051d5264b28980552b42518ec20bf3f6ccae8 Mon Sep 17 00:00:00 2001 From: "m.reschke" Date: Thu, 29 Sep 2016 15:04:00 +0200 Subject: [PATCH] Initial Commit --- .gitignore | 1 + README.md | 5 +++++ backup/.empty | 0 db-backup.sh | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 .gitignore create mode 100644 backup/.empty create mode 100644 db-backup.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/README.md b/README.md index b1e6b03..fb27498 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ # bash-database-backup Simple Bash Script to Backup a Database + +Modify the options in db-backup.sh to your needs! + +Run for the backup: + # ./db-backup.sh \ No newline at end of file diff --git a/backup/.empty b/backup/.empty new file mode 100644 index 0000000..e69de29 diff --git a/db-backup.sh b/db-backup.sh new file mode 100644 index 0000000..20764f1 --- /dev/null +++ b/db-backup.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +###################################################################################################### +############## Configuration ######################################################################## +###################################################################################################### + +# Database credentials +user="" +password="" +host="" +db_name="" + +# Other options +backup_path="/home//backup" +date=$(date +"%d-%b-%Y") +compressLevel=9 + +###################################################################################################### +############## Script Logik Starts here ############################################################## +###################################################################################################### + +# Set default file permissions +umask 177 + +# Dump database into SQL file +mysqldump --user=$user --password=$password --host=$host $db_name > $backup_path/$db_name-$date.sql + +# compress the SQL file +cd $backup_path +gzip -f -$compressLevel $db_name-$date.sql + +# Delete files older than 30 days +find $backup_path/* -name *.sql -mtime +30 -exec rm {} \; \ No newline at end of file