Welcome Guest. Please Login or Register  


You are here: Index > Webuzo > General Support > Topic : My way to backup MYSQL and DATA to AWS S3



Threaded Mode | Print  

 My way to backup MYSQL and DATA to AWS S3, My way to backup MYSQL and DATA to AWS S3 (0 Replies, Read 31124 times)
itsme7815
Group: Member
Post Group: Newbie
Posts: 4
Status:
Hi,

First, english is not my language, so sorry for all the mistakes.

Below, here my ways and bash scripts to backup daily/weekly all the mysql databases and data to Amazon AWS S3

TIME TO COMPLETE : 30 min
Webuzo installed in CENTOS OS 7

Those scripts are working for webuzo (at least, for the actual version of webuzo)

Note : this script doesn't handle all the case of errors. It's working for my needs.
I don't provide any support (or fast answers). It could be a good start to make your own script, or not.
But again, it's not 100% sure this wil work in your case.

Create a dedicated username in AWS S3 for better security (with new api API only for backup)


******GUIDE BACKUP FILE TO S3****
We will use the tool S3cmd.

# Start by making sure your system is up-to-date:
Code
$ yum update


Install S3cmd
I tried to follow the install guide to here : https://github.com/s3tools/s3cmd/blob/master/INSTALL , but the RPM file didn't exist, so i used an other method (a bit dirty, but working)

** Get the number of the last version here : http://s3tools.org/download  (in my case, it's 2.0.1. Replace by the last version)
Code
$ wget http://ufpr.dl.sourceforge.net/project/s3tools/s3cmd/2.0.1/s3cmd-2.0.1.tar.gz
$ tar xzf s3cmd-2.0.1.tar.gz
$ cd s3cmd-2.0.1
$ yum install python-setuptools
$ sudo python setup.py install


Setup s3cmd
Code
$ s3cmd --configure

At the end of the process, the script will check if the S3 access is working
#To test s3cmd, display all buckets in your Amazon S3 account.
Code
$ s3cmd ls

#You should have the list of your S3 buckets. Otherwise, there is a problem

1.BACKUP MYSQL
The script will backup each database, one file = one database. This case, it won't block if there is any error in one of the table in one database

Download the bash file s3mysqlbackup.sh : https://pastebin.com/MCeV9BE4
** Edit et replace by your values the var :  mysqlpass, bucket, emails
Attribution : from https://gist.github.com/oodavid/2206527
I have edited the script of oodavid to make it working for webuzo (because the mysql tool mysqlydump is located to an other folder)

The root phpmyadmin password is on /var/webuzo/my.conf

Upload this new file in /root folder  (via filezilla or whatever)
Connect to your VPS/Server via SSH, and go to the /root folder

# Add the executable bit
Code
chmod +x s3mysqlbackup.sh

# Run the script to make sure it's all tickety boo
Code
./s3mysqlbackup.sh

** If you have at the end "Jobs a goodun", it's working.
You should also receive an email. If you want to remove the email notification, remove all the files after echo -e "\e[1;32mJobs a goodun\e[00m"

Double check in the bucket S3 if you find the backup. Also, try to download the files into your S3 to check if all is working



If you have this error /bin/bash^M: bad interpreter: No such file or directory
it's an error of the file setup.
So make :
Code
sed -i -e 's/\r$//' s3mysqlbackup.sh

More informations here : https://askubuntu.com/questions/304999/not-able-to-execute-a-sh-file-bin-bashm-bad-interpreter
If you are in notepad++, go on Edit/Convert/Convert file to Unix



If you want to backup only mysql database (and not data), just add the cron job now (step 3)

2.BACKUP FILES/DATA
For this step, we'll use the already build automatic schedule backup via webuzo dashboard (need webuzo paid licence)
**Webuzo Dashboard > Server Utilities > Webuzo Backup
Then, we'll synchronize with the backup and S3
In my code, I also remove the file in the server to keep only one version in S3
You can schedule any kind of backup type (full backup, home backup, data backup, mail backup).
More details about the webuzo backup here : https://www.webuzo.com/wiki/Webuzo_Backup_And_Restore
Personnaly, I make a full backup once a month, and a home backup every week.
You can setup a schedule backup via the webuzo dashboard on the morning, and setup the cron to be launched everyday on the evening (to be sure the automatic backup ended the backup).
This way, everyday , the script will check if there is any new files in the webuzo backup
In fact, you can even use this step to backup the mysql, but in my case, I prefer the precedent script to get a backup of each table separatly.
Because in some cases, the mysql dump can crash in case of table error.

Download the file s3folderbackup.sh : https://pastebin.com/60yj5Gnb
And replace by your variables (bucket, and # Email variables)

Upload the file, and connect via SSH to the /root folder
# Add the executable bit
Code
chmod +x s3folderbackup.sh

# Run the script to make sure it's all tickety boo
Code
./s3folderbackup.sh

You'll receive an email when the backup is working (or not)

3. SET UP the CRON JOBS
In my case, I setup schedule webuzo backup at 1h11 each day/week/month
Code
$ crontab -e
5 1 * * * bash /root/s3mysqlbackup.sh >/dev/null 2>&1
20 1 * * 0 bash /root/s3folderbackup.sh >/dev/null 2>&1


CTRL + Z  : to kill crontab
:wq : to save + exit

The command ">/dev/null 2>&1" is to not send a cron job email when the cron is executed.
So you can remove this part for testing purpose.
Note 1: this cron job email is different than the email sent via the S3 backup script. The cron job email is usually sent each time a cron is executed
Note 2 : I don't know why, but when I add the 2 cron job via the webuzo dashboard (under cron job utilities), it's not working. It's only working when I setup directly via ssh and the crontab command





**Update S3cmd from time to time
Code
yum upgrade s3cmd


Check quickly if all is working after each webuzo update. http://www.webuzo.com/blog/
RSS Feed : http://www.webuzo.com/blog/feed

I hope you like it
IP: --   

« Previous    Next »

Threaded Mode | Print  



Jump To :


Users viewing this topic
1 guests, 0 users.


All times are GMT. The time now is April 16, 2024, 11:45 am.

  Powered By AEF 1.0.8 © 2007-2008 Electron Inc.Queries: 10  |  Page Created In:0.025