|
1 | | -### Bash Backup Rotation Script |
2 | | - |
3 | | -### Description |
4 | | -This script allows you to create a backup rotation for your files and mysql database. The backup target can be local or remote (FTP). |
5 | | - |
6 | | -The script has 3 backup types |
7 | | - |
8 | | -- Daily backup |
9 | | -- Weekly backup (default : perform every sixth day of the week) |
10 | | -- Monthly backup (default : perform every first day of the month) |
11 | | - |
12 | | -This script allows you to customize where to backup each `backup type`. For example you can choose to do daily and weekly backup on local machine and monthly backup on a FTP server. |
13 | | - |
14 | | -Each type of backup will have a backup retention(copy). The default retention for every type of backup can be configured. |
15 | | - |
16 | | -The backup retention default day is : |
17 | | - |
18 | | -* Daily backup : 5 Day ( 5 daily backups ) |
19 | | -* Weekly backup : 14 Day ( ~2 weekly backups ) |
20 | | -* Monthly backup : 30 Day ( ~1 Monthly backups ) |
21 | | - |
22 | | -Please consider your storage size when chosing retention settings. |
23 | | - |
24 | | -### Table of Contents |
25 | | -1. [Usage Instruction](#usage_instruction) |
26 | | -2. [Backup Type Configuration](#backup_type_configuration) |
27 | | -3. [FTP Backup Configuration](#ftp_backup_configuration) |
28 | | -4. [Contribute and Contact](#contribute_and_contact) |
29 | | - |
30 | | -<div id='usage_instruction'> |
31 | | - |
32 | | -## 1. Usage Instruction |
33 | | - |
34 | | -1. Download the `backup_rotation.sh` script into your NIX server. |
35 | | - |
36 | | - wget https://raw.githubusercontent.com/todiadiyatmo/bash-backup-rotation-script/master/backup_rotation.sh |
37 | | - |
38 | | -2. Open the file using your favourite editor (ex :`nano` or `vim`) |
39 | | - |
40 | | - nano backup_rotation.sh |
41 | | - |
42 | | - or |
43 | | - |
44 | | - vim backup_rotation.sh |
45 | | - |
46 | | -3. Edit the configuration file. MYSQL configuration, for minimal `BACKUP_DIR`, `TARGET_DIR` must be filled. |
47 | | - |
48 | | - # The directory to be backup , DO NOT END THE DIRECTORY WITH BACKSLASH ! |
49 | | - TARGET_DIR=/target_directory |
50 | | - |
51 | | - # The backup directory , DO NOT END THE DIRECTORY WITH BACKSLASH ! |
52 | | - SOURCE_DIR=/your_backup_direcory |
53 | | - |
54 | | - # Admin email |
55 | | - |
56 | | - |
57 | | - # Number of day the daily backup keep |
58 | | - RETENTION_DAY=5 |
59 | | - |
60 | | - # Number of day the weekly backup keep |
61 | | - RETENTION_WEEK=14 |
62 | | - |
63 | | - # Number of day the monthly backup keep |
64 | | - RETENTION_MONTH=30 |
65 | | - |
66 | | - #Monthly date backup option (day of month) |
67 | | - MONTHLY_BACKUP_DATE=1 |
68 | | - |
69 | | - #Weekly day to backup option (day of week - 1 is monday ) |
70 | | - WEEKLY_BACKUP_DAY=6 |
71 | | - |
72 | | -4. Make the script executable |
73 | | - |
74 | | - chmod +x backup_rotation.sh |
75 | | - |
76 | | -5. Test the script (sudo may be required) |
77 | | - |
78 | | - bash backup_rotation.sh |
79 | | - |
80 | | -6. If the script runs correctly the file will be available in `TARGET_DIR`. Try to extract the file and check the contents |
81 | | - |
82 | | - tar -xJfv [filename].tar.xz |
83 | | - |
84 | | -7. To make the backup run daily, put it in a crontab |
85 | | - |
86 | | - crontab -e |
87 | | - |
88 | | - #put this line in crontab |
89 | | - #This will run it 10 minutes after midnight. |
90 | | - 10 0 * * * [path to your backup_rotation.sh] |
91 | | - |
92 | | -8. If crontab is not available, consult your distributions packages. Ubuntu Server includes it by default. |
93 | | - |
94 | | -<div id='backup_type_configuration'> |
95 | | - |
96 | | -## 2. Backup Type Configuration |
97 | | - |
98 | | -To customize the `backup type` you must alter the `LOCAL_BACKUP_OPTION` and `FTP_BACKUP_OPTION` in the configuration script. |
99 | | - |
100 | | -The configuration value of `LOCAL_BACKUP_OPTION` and `FTP_BACKUP_OPTION` can be view on the table below |
101 | | - |
102 | | - |
103 | | - |
104 | | -For example, if you want to do a daily backup on local and weekly on FTP you must fill both options like this: |
105 | | - |
106 | | - LOCAL_BACKUP_OPTION=1 |
107 | | - |
108 | | - FTP_BACKUP_OPTION=2 |
109 | | - |
110 | | -<div id='ftp_backup_configuration'> |
111 | | - |
112 | | -## 3. FTP Backup Configuration |
113 | | - |
114 | | -1. Make sure that you fill the `FTP_BACKUP_OPTION` with a correct value. |
115 | | -2. Fill out FTP configuration in the script. |
116 | | - |
117 | | - # ----------------- |
118 | | - # FTP Configuration |
119 | | - # Enter all data within the ' ' single quote ! |
120 | | - # ----------------- |
121 | | - |
122 | | - #This is the FTP servers host or IP address. |
123 | | - FTP_HOST='FTP HOST' |
124 | | - |
125 | | - #FTP PORT |
126 | | - FTP_PORT=21 |
127 | | - |
128 | | - #This is the FTP user that has access to the server. |
129 | | - FTP_USER='FTP USER' |
130 | | - |
131 | | - #This is the password for the FTP user. |
132 | | - FTP_PASSWORD='FTP_PASSWORD' |
133 | | - |
134 | | - #The backup directory on remote machine, DO NOT END THE DIRECTORY WITH BACKSLASH ! |
135 | | - FTP_TARGET_DIR='/remote_path' |
136 | | - |
137 | | -<div id='contribute_and_contact'> |
138 | | - |
139 | | -## 4. Contribute and Contact |
140 | | - |
141 | | -Everybody is welcome to fork and contribute. If you need to pull something just post it on the message board. |
| 1 | +# Bash Backup Rotation Script |
| 2 | + |
| 3 | +Simple script which can be easily modified if needed for backup rotation. This script use ssh and rsync for syncing |
| 4 | +This script is completely rewriten , old script can be found here : https://github.com/todiadiyatmo/bash-backup-rotation-script/tree/legacy-1.0.0 . |
| 5 | + |
| 6 | +## Feature |
| 7 | + |
| 8 | +- Daily, Weekly, Monthly backup script with number of retention (backup to keep) option |
| 9 | +- backup to local only, local + remote and remote only mode |
| 10 | +- 4 different backup script : |
| 11 | + - file backup with zip compression script |
| 12 | + - rsync script |
| 13 | + - mysql script |
| 14 | + - mysql with extrabackup script |
| 15 | +- Secure backup with SSH connection |
| 16 | + |
| 17 | + |
| 18 | +## Todo |
| 19 | + |
| 20 | +This release is still missing this feature from the old relesae |
| 21 | + |
| 22 | +- [ ] email notification |
| 23 | + |
| 24 | +# Usage |
| 25 | + |
| 26 | +## MySQL / MySQL Extrabackup / Zip File Backup |
| 27 | + |
| 28 | +- Copy script to desired location |
| 29 | +- Edit the parameter of the script, configure the `BACKUP_RETENTION_` to set the rotation / number of backup needed |
| 30 | + |
| 31 | +``` |
| 32 | +### User Pass Mysql ### |
| 33 | +USER=backup |
| 34 | +PASS=backup |
| 35 | +DBNAME=project_sql |
| 36 | +BACKUP_DIR="/root/backup" |
| 37 | +DST_HOST="user@host" |
| 38 | +REMOTE_DST_DIR="/root/backup" |
| 39 | +BACKUP_DAILY=true # kalau false ga dibackup |
| 40 | +BACKUP_WEEKLY=true # kalau false ga dibackup |
| 41 | +BACKUP_MONTHLY=true # kalau false ga dibackup |
| 42 | +BACKUP_RETENTION_DAILY=3 |
| 43 | +BACKUP_RETENTION_WEEKLY=3 |
| 44 | +BACKUP_RETENTION_MONTHLY=3 |
| 45 | +``` |
| 46 | +- test the script to make sure everything correct , ex : `mysql-backup-script.sh` |
| 47 | +- put script on cron to make sure it is running everyday at your desired time : `00 03 * * * backup.sh` |
| 48 | +- check your backup result |
| 49 | +- profit :) |
| 50 | + |
| 51 | +## Pull request and issue |
| 52 | +feel free to open pull request and submit bug ticket |
0 commit comments