Skip to content

Commit

Permalink
016 - Simple DB Backup
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBrauer committed Jan 16, 2017
1 parent bf44604 commit d535bca
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
5 changes: 5 additions & 0 deletions 016_2017-01-16_Shell_Simple-DB-Backup/README.md
Original file line number Diff line number Diff line change
@@ -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:** <https://codebrauer.github.io/100daysofcode/016_2017-01-16_Shell_Simple-DB-Backup/>
21 changes: 21 additions & 0 deletions 016_2017-01-16_Shell_Simple-DB-Backup/app.css
Original file line number Diff line number Diff line change
@@ -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;
}
24 changes: 24 additions & 0 deletions 016_2017-01-16_Shell_Simple-DB-Backup/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html><html>

<head>
<meta charset="utf-8">
<title>Simple DB Backup Script</title>
<meta name="theme-color" content="#666666">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Overpass+Mono" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="app.css">
</head>
<body>
<div class="container">
<h1>Built a simple database backup script</h1>
<p>
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 <code>-mtime +30</code> I use <code>-mmin +4320</code> (3 days) and extented the <code>DATE_TODAY</code> 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).
</p>
<script src="https://gist.github.com/CodeBrauer/2e1e392c0622f44b2aac47f257ff8c20.js"></script>
</div>

<script src="https://cdn.rawgit.com/CodeBrauer/ebf5d310e4703b1186e7384ca1e1405d/raw/c5c1e53a82ae8370979007f8db345870e1782b78/githubcorner.js"></script>
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');ga('create', 'UA-59784112-5', 'auto');ga('send', 'pageview');</script>
</body>

</html>
18 changes: 18 additions & 0 deletions 016_2017-01-16_Shell_Simple-DB-Backup/mysql_backup.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d535bca

Please sign in to comment.