Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
February 09, 2012, 09:06:29 PM

Pages: [1]   Go Down
  Print  
Author Topic: How to automate backups via cron, plus backup MySQL and Postgres databases  (Read 1205 times)
starrychloe
Newbie
*
Offline Offline

Posts: 1


« on: April 17, 2009, 11:59:16 AM »

I could not post this in How To for some reason. I saw a post on this subject but it was a little overkill. Automate FTP... to where? Your host is the FTP server. Mail backups... are you kidding? As big as they are? The cPanel full backups have a duplicate .tar.gz file inside of them, and copy stuff I don't need. I was hit by a spam virus so was motivated to create nightly backups. Here are several options.

1. Install www.netdrive.net and setup your account to login in when Windows starts on drive X:. Netdrive is free and turns a FTP server into a drive letter.

2. Install www.crashplan.com and set it up with a friend to do automatic backups. Include drive X: along with your other files and the directories you want. Crashplan is free and backs up your computer to a friend's, and vice versa. This is the easiest way, but probably slowest.

3. Create this shell script in your FTP home directory (X:\backup.sh). Replace the xxxxxx with your passwords,  uuuuuuu with your username, and mmmmmm with your MySQL DB name, and ppppppp with your Postgres DB name. -9 means maximum compression. If you want to keep the same filename, you can get rid of the $date, {$date}, and 20??????.

Code:
#!/bin/sh
rm ~/backup20??????.tar.gz # remove old backup file
rm ~/backup20??????mmmmm.sql.gz
rm ~/backup20??????mmmmmm.sql.gz
rm ~/backup20??????ppppppp.sql.gz
date=`date +%Y%m%d`
tar cf ~/backup$date.tar public_html
gzip -9 ~/backup$date.tar
mysqldump -u uuuuu --password=xxxxx mmmmmm | gzip -9 > backup${date}mmmmm.sql.gz
mysqldump -u uuuuu --password=xxxxxxx mmmmmmm | gzip -9 > backup${date}mmmmmm.sql.gz
export PGPASSWORD=xxxxxxxxx
pg_dump -U uuuu pppppppp | gzip -9 > backup${date}ppppppp.sql.gz

4. Setup a cron in your control panel to run this script once a night or week or month.

5. Create this batch file on your computer (backupweb.bat). /d means don't copy if file exists with same date, /y means overwrite existing file.

Code:
xcopy /d /y x:\*.gz "c:\Documents and Settings\Chloe\My Documents\Lunarpages"

6. Create a scheduled task in Windows control panel to run this batch every night, about 10-15 minutes after your cron job. Done!

7. Download and install Unison at http://www.cis.upenn.edu/~bcpierce/unison/ and synchronize X:\ with a directory on your computer. Unison is like Dropbox or Synchplicity, only 10 times more complicated, free, and without limits.

8. Create a scheduled task to run Unison.

9. If you want to get to the data inside the .tar.gz files, install www.cygwin.com (only the basics). It's free and makes your command line like Linux. Use "gzip -dc file.tar.gz | tar -t | less" to see the archive, and "gzip -dc file.tar.gz | tar -x" to extract the files. I believe WinRAR also can see inside .tar.gz files.

You don't have to do all of the above. Unison is very slow over Netdrive. Would only be good for small sites. Crashplan is also probably slow over Netdrive. Compressing all files then FTP/copy is the fastest way onto your computer.

Logged
Mitch
Berserker Poster
*****
Offline Offline

Posts: 12838


WWW
« Reply #1 on: April 17, 2009, 12:03:00 PM »

Thanks for sharing!   Welcome
Logged

New to Web Site Hosting? Check Out the Lunarpages Blog Hosting Guide!


Follow us @lunarpages on Twitter!
Important Threads: Read This Before Posting! | Lunarforums Rules! | Mitch's Link of the Day!
Also, be sure to check out and subscribe to the Lunartics Blog and the Lunarpages Newsletter !

Need Web Hosting Help? Check out the Lunarpages Web Hosting Wiki. It has tons of tips, tutorials and resources!
Pages: [1]   Go Up
  Print  
 
Jump to: