Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
n0v3xx committed Sep 29, 2016
1 parent 0560909 commit c92051d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Empty file added backup/.empty
Empty file.
33 changes: 33 additions & 0 deletions db-backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

######################################################################################################
############## Configuration ########################################################################
######################################################################################################

# Database credentials
user=""
password=""
host=""
db_name=""

# Other options
backup_path="/home/<user>/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 {} \;

0 comments on commit c92051d

Please sign in to comment.