Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Help Groups for Snitz Forums 2000 Users
 Help: Database: MySql
 Cron Jobs - setting one up to back up database ?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Webbo
Average Member

United Kingdom
982 Posts

Posted - 13 December 2017 :  22:08:51  Show Profile  Visit Webbo's Homepage  Reply with Quote
Is there a simple to follow guide that explains how to set up a Cron job using SSH on a Linux server to back up a MySQL database on a daily basis and email me to confirm if successful or not?

I've found several which seem to be very long winded and often over my head

HuwR
Forum Admin

United Kingdom
20550 Posts

Posted - 17 December 2017 :  13:08:12  Show Profile  Visit HuwR's Homepage  Reply with Quote
it shouldn't be too longwinded. I assume you wish to execute a local script to back up a hosted db?

what flavour of Linux is your client machine ?

MVC .net dev/test site | MVC .net running on Raspberry Pi
Go to Top of Page

Webbo
Average Member

United Kingdom
982 Posts

Posted - 20 December 2017 :  23:01:11  Show Profile  Visit Webbo's Homepage  Reply with Quote
Hi Huw, CentOS6 x86_64 and yes, a local to hosted

I use MySQL Workbench 6.3 and at the moment am doing it manually
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20550 Posts

Posted - 21 December 2017 :  09:06:00  Show Profile  Visit HuwR's Homepage  Reply with Quote
Ok, I will post something for you later today

MVC .net dev/test site | MVC .net running on Raspberry Pi
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20550 Posts

Posted - 21 December 2017 :  20:36:19  Show Profile  Visit HuwR's Homepage  Reply with Quote
basically you can connect via ssh and backup your database from the command line using something like the following, it should backup your database to your local machine, just change the necessary values

ssh -C remoteuser@remote_host mysqldump -u MYSQL_USER -p'MYSQL_PASSWORD' YOUR_DATABASE | gzip -c | cat > ~/backup.sql.gz

you then need to add a cron job, probably for the root user so run <b>crontab -e -u root </b>and add a line like below and save it. It will run at 6am every day

0 6 * * * ssh -C remoteuser@remote_host mysqldump -u MYSQL_USER -p'MYSQL_PASSWORD' YOUR_DATABASE | gzip -c | cat > ~/backup.sql.gz

change the cron string 0 6 * * * to suit your needs as below

•Crontab Format:
MIN HOUR DOM MON DOW CMD
•Format Meanings and Allowed Value:
•MIN Minute field 0 to 59
•HOUR Hour field 0 to 23
•DOM Day of Month 1-31
•MON Month field 1-12
•DOW Day Of Week 0-6
•CMD Command Any command to be executed.




MVC .net dev/test site | MVC .net running on Raspberry Pi
Go to Top of Page

Webbo
Average Member

United Kingdom
982 Posts

Posted - 21 December 2017 :  22:11:58  Show Profile  Visit Webbo's Homepage  Reply with Quote
Thanks Huw, I'll have a go at setting it up later tomorrow
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000 Version 3.4.07