Skip to content

Commit 52d8b5e

Browse files
committed
Adding automated deletions of files
1 parent a905e1f commit 52d8b5e

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22

3+
34
# Automated Server Backups!
45

56
### The Mission
@@ -110,13 +111,11 @@ tar czvfP $dest/$archive_file $backup_files
110111
```
111112
Confused by `czvfP` ?
112113

113-
| option | description |
114-
|--|--|
115-
|`-c, --create`| create a new archive |
116-
|`-z, --gzip`| filter the archive through gzip |
117-
|`-v, --verbose`| verbosely list files processed |
118-
|`-f, --file=ARCHIVE`| use archive file or device ARCHIVE |
119-
|`-p, --preserve-permissions`| extract information about file permissions |
114+
- `-c` create a new archive
115+
- `-z` filter the archive through gzip
116+
- `-v` verbosely list files processed
117+
- `-f` use archive file or device ARCHIVE
118+
- `-p` extract information about file permissions
120119

121120
Type `$ man tar` or visit the [docs](https://www.systutorials.com/docs/linux/man/1-tar/) for more information.
122121

@@ -240,14 +239,27 @@ Unpack the downloaded file
240239
$ tar -xvzf host-mysql-18-03-25.tar
241240
```
242241
243-
## Thoughts:
244-
Currently we are generating the file names for our server backup with the current date. This could be a problem if you are running the script more than once a day. Currently the file will be overwritten.
242+
## Enhancements
245243
246-
Currently there is nothing which handles old server backups. If you run daily jobs you will hit the disk space limit soon.
244+
### Delete old backup files
245+
What to do with old back up files? You may don't need them anymore. If you run jobs on a daily basis you will hit the disk space limit soon. You could include a "old-file-deleter" in your script. Let's say we want to delete all files which are older than 14 days.
247246
248-
What would this script look like for a windows server backup?
247+
```bash
248+
# place at the end of backup.sh
249+
find /mnt/backup -mtime +14 -type f -delete
250+
```
251+
- `/mnt/backup` to search in
252+
- `-mtime +14` older than 14 days
253+
- `-type f` only files
254+
- `-delete` no surprise. **Remove it to test your `find` filter before executing the whole command**
249255
250-
How to include this script in CMS ?
256+
## Thoughts:
257+
258+
- Currently we are generating the file names for our server backup with
259+
the current date. This could be a problem if you are running the
260+
script more than once a day. Currently the file will be overwritten.
261+
- What would this script look like for a windows server backup?
262+
- How to include this script in CMS ?
251263
252264
## Links:
253265
@@ -256,4 +268,12 @@ How to include this script in CMS ?
256268
- Crontabs https://www.computerhope.com/unix/ucrontab.htm
257269
- Crontab examples https://tecadmin.net/crontab-in-linux-with-20-examples-of-cron-schedule/
258270
271+
## Author
272+
273+
__Script:__ <https://github.com/zauberware/automated-server-backups>
274+
275+
__Author website:__ [https://www.zauberware.com](https://www.zauberware.com)
276+
__Author:__ zauberware technologies / Simon Franzen <simon@zauberware.com>
277+
278+
![zauberware technologies](https://avatars3.githubusercontent.com/u/1753330?s=200&v=4)
259279

backup.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,22 @@ echo
4242
echo "================================================================="
4343
echo ""
4444

45-
# backup the files using tar.
45+
# database dump in temp file
4646
tar czvfP $dest/$archive_file $backup_files
4747

48-
# database backup
48+
# pack the sql dump with tar and remove dump
4949
mysqldump --user root --routines --triggers --single-transaction --databases $backup_databases > "$dest/sql_dump.sql"
50-
tar czfP $dest/$mysql_file "$dest/sql_dump.sql" && rm $dest/sql_dump.sql
50+
tar czfP $dest/$mysql_file "$dest/sql_dump.sql"
51+
rm $dest/sql_dump.sql
5152

5253
# print end status message
5354
echo
5455
echo "Backup SUCCESS"
5556
date
57+
echo
58+
echo "Delete old files"
59+
find $dest -mtime +14 -type f -delete
60+
echo
5661

57-
# long listing of files in $dest to check file sizes
62+
# echo generated files
5863
ls -lh $dest

0 commit comments

Comments
 (0)