lqdung1992 / autobackup

Incremental backup

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AutomysqlBackup
-------------------------
.. INDEX
-------------------------
Disclaimer
Install
Usage
Configuration Options
Encryption
Backup rotation
Restoring



.. DISCLAIMER
-------------------------
I take no resposibility for any data loss or corruption when using this script.
This script will not help in the event of a hard drive crash. If a copy of the
backup has not been stored offline or on another PC. You should copy your backups
offline regularly for best protection.

Happy backing up...



.. INSTALL
-------------------------
Extract the package into a directory. If you are reading this you have probably done
this already.

To install the Automysqlbackup the easy way.
1. Run the install.sh script.
2. Edit the /etc/automysqlbackup/myserver.conf file to customise your settings.
3. See usage section.

To install it manually (the hard way).
1. Create the /etc/automysqlbackup directory.
2. Copy in the automysqlbackup.conf file.
3. Copy the automysqlbackup file to /usr/local/bin and make executable.
4. cp /etc/automysqlbackup/automysqlbackup.conf /etc/automysqlbackup/myserver.conf
5. Edit the /etc/automysqlbackup/myserver.conf file to customise your settings.
6. See usage section.

To install incremental backup
1. cp mysql-incremental /etc/automysqlbackup/
2. chmod 755 /etc/automysqlbackup/mysql-incremental
3. cp mysql-backup-post /etc/automysqlbackup/
4. chmod 755 /etc/automysqlbackup/mysql-backup-post
5. cp mysql-backup-pre /etc/automysqlbackup/
6. chmod 755 /etc/automysqlbackup/mysql-backup-pre

Config:
```
CONFIG_mysql_dump_username='Mysql user name. It must has privileges to get Lock'
CONFIG_mysql_dump_password='Password'
CONFIG_backup_dir='The backup directory you want to store full and incremental backup'
CONFIG_db_names=('databaseName1' 'databaseName2' )
CONFIG_db_month_names=('databaseName1' 'databaseName2' )
CONFIG_mysql_dump_master_data=2
CONFIG_prebackup="/etc/automysqlbackup/mysql-backup-pre"
CONFIG_postbackup="/etc/automysqlbackup/mysql-backup-post"
```

.. USAGE
-------------------------

Automysqlbackup can be run a number of ways, you can choose which is best for you.

1. Create a script as below called runmysqlbackup using the lines below:

#~~~~ Copy From Below Here ~~~~
#!/bin/sh

/usr/local/bin/automysqlbackup /etc/automysqlbackup/myserver.conf

chown root.root /var/backup/db* -R
find /var/backup/db* -type f -exec chmod 400 {} \;
find /var/backup/db* -type d -exec chmod 700 {} \;

#~~~~~ Copy To Above Here ~~~~

2. Save it to a suitable location or copy it to your /etc/cron.daily folder. 

3. Make it executable, i.e. chmod +x /etc/cron.daily/runmysqlbackup.


The backup can be run from the command line simply by running the following command.

  automysqlbackup /etc/automysqlbackup/myserver.conf

If you don't supply an argument for automysqlbackup, the default configuration
in the program automysqlbackup will be used unless a global file

  CONFIG_configfile="/etc/automysqlbackup/automysqlbackup.conf"

exists.

You can just copy the supplied automysqlbackup.conf as many times as you want
and use for separate configurations, i.e. for example different mysql servers.

!!! NEW !!!
----------
As of version 3.0 we have added differential backups using the program diff. In an
effort to make the reconstruction of the full archives more user friendly, we
added new functionality to the script. Therefore, while preserving the old syntax,
we created options for the script, so that the new functions can be accessed.

Usage automysqlbackup options -cblh
-c CONFIG_FILE  Specify optional config file.
-b      Use backup method.
-l      List manifest entries.
-h      Show this help.

If you use these options, you have to specify everything according to them and can't
mix the old syntax with the new one. Example:

before (still valid!):

  >> automysqlbackup "myconfig.conf"

now:

  >> automysqlbackup -c "myconfig.conf" -b

which is equivalent to

  >> automysqlbackup -bc "myconfig.conf"

or in English: The order of the options doesn't matter, however those options expecting
arguments, have to be placed right before the argument (as seen above).

The option '-l' (List manifest entries) finds all Manifest files in your configuration
directory (you need to specify your optional config file - otherwise a fallback will be
used: global config file -> program internal default options). It then filters from which
databases these are and presents you with a list (you can select more than one!) of them.
Once you have chosen, you will be given a list of Manifest files, from which you choose
again and after that from which you choose differential files. When you have completed
all your selections, a list of selected differential files will be shown. You may then
choose what you want to be done with/to those files. At the moment the options are:
- create full backup out of differential one
- remove the differential backup and its Manifest entry.


.. CONFIGURATION OPTIONS
-------------------------

!! "automysqlbackup" program contains a default configuration that should not be changed:

The global config file which overwrites the default configuration is located here
"/etc/automysqlbackup/automysqlbackup.conf" by default.

Please take a look at the supplied "automysqlbackup.conf" for information about the configuration options.

Default configuration
CONFIG_configfile="/etc/automysqlbackup/automysqlbackup.conf"
CONFIG_backup_dir='/var/backup/db'
CONFIG_do_monthly="01"
CONFIG_do_weekly="5"
CONFIG_rotation_daily=6
CONFIG_rotation_weekly=35
CONFIG_rotation_monthly=150
CONFIG_mysql_dump_usessl='yes'
CONFIG_mysql_dump_username='root'
CONFIG_mysql_dump_password=''
CONFIG_mysql_dump_host='localhost'
CONFIG_mysql_dump_socket=''
CONFIG_mysql_dump_create_database='no'
CONFIG_mysql_dump_use_separate_dirs='yes'
CONFIG_mysql_dump_compression='gzip'
CONFIG_mysql_dump_commcomp='no'
CONFIG_mysql_dump_latest='no'
CONFIG_mysql_dump_max_allowed_packet=''
CONFIG_db_names=()
CONFIG_db_month_names=()
CONFIG_db_exclude=( 'information_schema' )
CONFIG_mailcontent='log'
CONFIG_mail_maxattsize=4000
CONFIG_mail_address='root'
CONFIG_encrypt='no'
CONFIG_encrypt_password='password0123'

!! automysqlbackup (the shell program) accepts one parameter, the filename of a configuration file. The entries in there will supersede all others.

Please take a look at the supplied "automysqlbackup.conf" for information about the configuration options.



.. ENCRYPTION
-------------------------

To decrypt run (replace bz2 with gz if using gzip):

openssl enc -aes-256-cbc -d -in encrypted_file_name(ex: *.enc.bz2) -out outputfilename.bz2 -pass pass:PASSWORD-USED-TO-ENCRYPT



.. BACKUP ROTATION
-------------------------

Daily Backups are rotated weekly.
Weekly Backups are run on fridays, unless otherwise specified via CONFIG_do_weekly.
Weekly Backups are rotated on a 5 week cycle, unless otherwise specified via CONFIG_rotation_weekly.
Monthly Backups are run on the 1st of the month, unless otherwise specified via CONFIG_do_monthly.
Monthly Backups are rotated on a 5 month cycle, unless otherwise specified via CONFIG_rotation_monthly.

Suggestion: It may be a good idea to copy monthly backups offline or to another server.



.. RESTORING
-------------------------

Firstly you will need to uncompress the backup file and decrypt it if encryption was used (see encryption section).

eg.
gunzip file.gz (or bunzip2 file.bz2)

Next you will need to use the mysql client to restore the DB from the sql file.

eg.
  mysql --user=username --pass=password --host=dbserver database < /path/file.sql
or
  mysql --user=username --pass=password --host=dbserver -e "source /path/file.sql" database

NOTE: Make sure you use "<" and not ">" in the above command because you are piping the file.sql to mysql and not the other way around.

## Update my.cnf:
--------------------
Edit the MySQL configuration file:

nano /etc/mysql/my.cnf

1- BinLog Format

Due to some limitation on STATEMENT format, my recommendation is to set ROW based format. For more information please see the 'troubleshoot' section in this howto. You can check the type of binary log format by executing "select @@binlog_format;" query. To modify logbin format , you must add binlog_format = ROW� to mysql.conf or my.cnf .

2- binlog_do_db

You must specify the databases that you intend to have the related changes in the binary log. Please note if you do not specify any database, any change on any database will be logged into binary log. In this case, if you chose STATEMENT format, maybe you have some trouble when restoring from incremental backup and binlog files. You can add databases to this option:

binlog_do_db = DATABASENAME1
binlog_do_db = DATABASENAME2

3- expire_logs_days

To have binary log files for a longer time, you can increase this parameter to a higher value. My recommendation is 60 days. So you must add or change it to "expire_logs_days = 60".

4- log-bin

The directory where the binary logs will be stored. In old MySQL versions, mysql-incremenetal might not be able to find the correct path. So if you get an error about this after executing mysql-incremental, you must update mysql-incremental script and set the binary log path.

5- log_slave_updates

If you are setting up mysql-incremental backup on a slave server, you must enable this option. Normally, a slave does not log updates to its own binary log as they were received from a master server. This option tells the slave to log the updates performed by its SQL threads to its own binary log. http://dev.mysql.com/doc/refman/5.1/en/replication-options-slave.html#option_mysqld_log-slave-updates

## Run automysqlbackup
Run automysqlbackup manually to have at least one full backup from your specified databases.

automysqlbackup

After executing the command successfully, check the /[BackupDirInAutomysqlbackup]/status/backup_info file for the newly added information about the daily backup. For error details, check /var/log/Backup_Post_Pre_log . The backup file will be stored in the directory /[BackupDirInAutomysqlbackup]/daily/[DatabaseName]/ .

## Run mysql-incremental
Run mysql-incremental manually now to have at least one hourly backup.

mysql-incremental

In case of an error, the details are logged in the file "/var/log/Backup_Incremental_Log" . The incremental backup files will be stored in the directory /[BackupDirInAutomysqlbackup]/IncrementalBackup/ .

## crontab
crontab -e
```
5 00 * * * root /usr/local/bin/automysqlbackup
25 *  * * * root  /etc/automysqlbackup/mysql-incremental
```

## REF:
https://www.howtoforge.com/tutorial/mysql-incremental-backup-point-in-time-recovery/#run-automysqlbackup

About

Incremental backup

License:GNU General Public License v2.0


Languages

Language:Shell 100.0%