Summarize the characteristics of backup.sh:
1, support the MYSQL/MARIADB database full volume backup;
2, support the designated directory or file backup;
3, supporting the encrypted backup files;
4, support one key to upload to Google Drive (need to install gdrive and configure first)
August 21, 2016 update:
1, add: Specify MYSQL/MARIADB database name for backup, you can specify multiple;
2, add: Delete the specified number of days local old backup files.
Tutorial Mode Open:
1, download the script and give execution permissions
wget https://github.com/teddysun/across/raw/master/backup.sh
chmod +x backup.sh
2, modify and configure the script
Please use VIM or nano tools to modify.
Some instructions on variable names:
ENCRYPTFLG (encrypted flg,true is encrypted, false is unencrypted, default is encryption)
BackupPass (encryption password, important, be sure to modify)
Localdir (backup directory, you can specify yourself)
TempDir (The temporary directory of the backup directory, you can specify it yourself)
LOGFILE (log file path generated by script run)
Mysql_root_password (ROOT user password for MySQL or mariadb)
Mysql_database_name (Specify MySQL database name, leave blank to back up all databases)
※mysql_database_name is an array variable that can specify more than one. Examples are as follows:
mysql_database_name[0]= "phpMyAdmin"
mysql_database_name[1]= "Test"
Backup (a list of specified directories or files that need to be backed up, left blank to do not back up directories or files)
※backup is an array variable that can specify more than one. Examples are as follows:
backup[0]= "/data/www/default/test.tgz"
backup[1]= "/data/www/default/test/"
backup[2]= "/data/www/default/test2/"
Localagedailies (Specify how many days after the local old backup file is deleted, default is 7 days)
Notes on some caveats:
1 script needs to be executed with root user;
2 script needs to use OpenSSL to encrypt, please install beforehand;
3 script defaults back up all the databases (full-volume backup);
4 The decryption command for the backup file is as follows:
OpenSSL enc-aes256-in [ENCRYPTED BACKUP]-out decrypted_backup.tgz-pass Pass:[backuppass]-D-MD SHA1
5 After the backup file is decrypted, the decompression command is as follows:
TAR-ZXPF [decryption BACKUP FILE]
Explain the argument-P:
The tar compressed files are all relative paths by default. The addition of-p is for tar to compress files with absolute paths. Therefore, the decompression should also take a-p parameter.
3. Configure Gdrive command
Gdrive is a command-line tool for Google Drive upload and download operations. Official website:
Https://github.com/prasmussen/gdrive
Of course, you can use the following command to install Gdrive.
X86_64 (64-bit):
Wget-o/usr/bin/gdrive http://dl.teddysun.com/files/gdrive-linux-x64
chmod +x/usr/bin/gdrive
I386 (32-bit)
Wget-o/usr/bin/gdrive http://dl.teddysun.com/files/gdrive-linux-386
chmod +x/usr/bin/gdrive
Then, run the following command to begin obtaining authorization:
Gdrive List
Follow the prompts to open the URL given by the Gdrive browser, click Accept (Accept), and then paste the displayed string from the browser back to the command line to complete the authorization.
4. Run the script to start the backup
./backup.sh
The script displays the backup progress by default and then counts the time it takes.
If you want to add a script to cron Autorun, you don't need the foreground to display the backup progress, just write the log.
This time you need to change the log function in the script a little bit.
Log () {
echo "$" (date "+%y-%m-%d%h:%m:%s") "$"
Echo-e "$" (date "+%y-%m-%d%h:%m:%s") "$" >> ${logfile}
}
To
Log () {
Echo-e "$" (date "+%y-%m-%d%h:%m:%s") "$" >> ${logfile}
}
There are no more details about how to use cron automatic backup.