-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea |
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
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.
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
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 {} \; |