From d535bcab7582348dfaa48c7e70abcf2c4ec47a6d Mon Sep 17 00:00:00 2001 From: CodeBrauer Date: Tue, 17 Jan 2017 00:00:50 +0100 Subject: [PATCH] 016 - Simple DB Backup --- .../README.md | 5 ++++ 016_2017-01-16_Shell_Simple-DB-Backup/app.css | 21 ++++++++++++++++ .../index.html | 24 +++++++++++++++++++ .../mysql_backup.sh | 18 ++++++++++++++ README.md | 4 ++++ 5 files changed, 72 insertions(+) create mode 100644 016_2017-01-16_Shell_Simple-DB-Backup/README.md create mode 100644 016_2017-01-16_Shell_Simple-DB-Backup/app.css create mode 100644 016_2017-01-16_Shell_Simple-DB-Backup/index.html create mode 100644 016_2017-01-16_Shell_Simple-DB-Backup/mysql_backup.sh diff --git a/016_2017-01-16_Shell_Simple-DB-Backup/README.md b/016_2017-01-16_Shell_Simple-DB-Backup/README.md new file mode 100644 index 0000000..4a19385 --- /dev/null +++ b/016_2017-01-16_Shell_Simple-DB-Backup/README.md @@ -0,0 +1,5 @@ +# #016 2017-01-16: Simple DB Backup + +Currently in use on one of my test servers. But have also a modified version running on my MacBook, if things go terribly wrong. So instead `-mtime +30` I use `-mmin +4320` (3 days) and extented the `DATE_TODAY` variable. So I have now always a backup of at least 3 days (every 15 minutes) of my MacBook saved on my NAS. (Of cause only if my MacBook is connected to my home network). + +**Demo:** \ No newline at end of file diff --git a/016_2017-01-16_Shell_Simple-DB-Backup/app.css b/016_2017-01-16_Shell_Simple-DB-Backup/app.css new file mode 100644 index 0000000..ae3fa98 --- /dev/null +++ b/016_2017-01-16_Shell_Simple-DB-Backup/app.css @@ -0,0 +1,21 @@ +body { + padding: 0; + margin: 0; + font-family: 'Overpass Mono', sans-serif; + background: #fafafa; + color: #222; +} + +.container { + max-width: 600px; + width: 100%; + margin: 0 auto; + text-align: justify; +} + +code { + font-family: 'Overpass Mono', sans-serif; + background: #ddd; + padding: 0 5px; + border-radius: 3px; +} \ No newline at end of file diff --git a/016_2017-01-16_Shell_Simple-DB-Backup/index.html b/016_2017-01-16_Shell_Simple-DB-Backup/index.html new file mode 100644 index 0000000..dd270ed --- /dev/null +++ b/016_2017-01-16_Shell_Simple-DB-Backup/index.html @@ -0,0 +1,24 @@ + + + + + Simple DB Backup Script + + + + + + +
+

Built a simple database backup script

+

+ Currently in use on one of my test servers. But have also a modified version running on my MacBook, if things go terribly wrong. So instead -mtime +30 I use -mmin +4320 (3 days) and extented the DATE_TODAY variable. So I have now always a backup of at least 3 days (every 15 minutes) of my MacBook saved on my NAS. (Of cause only if my MacBook is connected to my home network). +

+ +
+ + + + + + diff --git a/016_2017-01-16_Shell_Simple-DB-Backup/mysql_backup.sh b/016_2017-01-16_Shell_Simple-DB-Backup/mysql_backup.sh new file mode 100644 index 0000000..39d58f9 --- /dev/null +++ b/016_2017-01-16_Shell_Simple-DB-Backup/mysql_backup.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +cd /var/backups/mysql_databases/ + +HOST="10.0.0.1" +USER="backupuser" +PASS="iezaakeXiecheik1yaeSheish4see5Xi" + +DATE_TODAY=$(date +"%Y-%m-%d") + +# dump it +mysqldump -h $HOST -u $USER -p$PASS --all-databases > db_$DATE_TODAY.sql + +# compress! +gzip -5 -f db_$DATE_TODAY.sql + +# delete files that are older than 30 days +find . -mtime +30 -type f -delete \ No newline at end of file diff --git a/README.md b/README.md index db7e941..29c5f75 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ A repo with 100 daily small projects (from 2017-01-01 till 2017-04-17) - every d Goal: Get a better coder, face up to new challenges, improve skills! +## Day 016 (Shell) + +[[Script]](https://codebrauer.github.io/100daysofcode/016_2017-01-16_Shell_Simple-DB-Backup) - Coded a shellscript that backups all mysql databases, compress it and deletes old backups. + ## Day 015 (PHP) [[Demo]](https://codebrauer.github.io/100daysofcode/015_2017-01-15_PHP_ForestPoll) - Built a [Strawpoll](http://strawpoll.me) clone in PHP.