Log in

View Full Version : Friendly reminder: backup, backup, backup.


Guest210212002
02-24-2008, 11:40 AM
You know you're out there, Mr. I-Just-Install-Plugins-At-Will guy. ;) When you install something, anything, back up your db first!. It's rarely the hack's fault when your tables crash. This morning I installed one of Paul's mods, and my mysql service timed out in the middle of it. This isn't Paul's fault, or the hack - it's just bad luck.

Fortunately, an hour later and a couple of cups of coffee and my site's good to go because I am a total fanatic for backing up. If you have SSH access, it's one command. Make a shell script. Stick this in it:


# Site Backup
mysqldump --opt -Q -u username -ppassword dbname > /path/to/your/backups/db-`date --iso-8601`.sql

Run it, and it'll make a datestamped backup of your DB. Then install your product. If it's a clean install, just remove the file. The process is quick and painless, and will no doubt save you hours of frustrating table repairs, angry vb.org PM's to boofo for no reason*, and grey hairs.

So before you click that Import Product link, do yourself a favor and back your stuff up!. :)

*that's what I do, anyway

--------------- Added 1203860745 at 1203860745 ---------------

Also, don't post things in the wrong forum like I just did. You'll feel silly. :D

(Moved now :D)

Lynne
02-24-2008, 03:27 PM
Very good advice! I must admit that I often forget to backup prior to adding a Mod. I always add the mod to my test site first, and if there are no problems, then I add it to my real site. (Which reminds me that I need to backup my test site!).

Also, another good thing is to remember to backup your files also. If you don't store attachments/avatars/etc in the database, then they are in the filesystem and won't get backed up when you backup your database!

nexialys
02-24-2008, 03:50 PM
This have to be the Tip of the Month... ;)
(and we can repeat it monthly!)

Boofo
02-24-2008, 04:11 PM
It might even rate a weekly shout around here. ;)

Guest210212002
02-24-2008, 06:15 PM
Very good advice! I must admit that I often forget to backup prior to adding a Mod. I always add the mod to my test site first, and if there are no problems, then I add it to my real site. (Which reminds me that I need to backup my test site!).

Also, another good thing is to remember to backup your files also. If you don't store attachments/avatars/etc in the database, then they are in the filesystem and won't get backed up when you backup your database!

I actually use the db script in cron.daily, and toss this guy in cron.weekly to nab the filesystem.


# Filesystem backup
tar -czf /path/to/backups/sitename-`date --iso-8601`.tar.gz /path/to/httpdocs/

Boofo
02-24-2008, 06:42 PM
Chris, can you PM exactly what you use for the file backups? I'm not sure I understand it fully.

@ Lynne - Thanks for the reminder on the file backups. Great idea! ;)

Lynne
02-24-2008, 06:45 PM
I wrote a script which I use to backup all my files. I run the attachment one once a week (7 GB of attachments) and the one for avatars, torrents, profile pics everynight. But, I also have all my files rsynced to an offsite server every night.

Guest210212002
02-24-2008, 06:53 PM
Chris, can you PM exactly what you use for the file backups? I'm not sure I understand it fully.

@ Lynne - Thanks for the reminder on the file backups. Great idea! ;)

I actually wrote it all up once. Here's the filesystem howto:

https://vborg.vbsupport.ru/showthread.php?t=105728

It's the same thing for the DB. In /etc/cron.daily I have a script called backup.sh, that contains this:


# Sevenstring.org Backup
mysqldump --opt -Q -u username -ppassword dbname > /path/to/your/backups/sevenstring-`date --iso-8601`.sql
Sleep 5
# Client 1 Backup
mysqldump --opt -Q -u username -ppassword dbname > /path/to/your/backups/client1-`date --iso-8601`.sql
sleep 5
# Client 2 Backup
mysqldump --opt -Q -u username -ppassword dbname > /path/to/your/backups/

And in /etc/cron.weekly, another file called weekly.sh that contains that, with the filesystem tacked on the end, like this:


#! /bin/bash
# Compressed Directory Tree Backup
tar -czvf /your/backup/folder/sitedata-`date --iso-8601`.tar.gz /path/to/your/siteroot/httpdocs/
# Sevenstring.org Backup
mysqldump --opt -Q -u username -ppassword dbname > /path/to/your/backups/sevenstring-`date --iso-8601`.sql
Sleep 5
# Client 1 Backup
mysqldump --opt -Q -u username -ppassword dbname > /path/to/your/backups/client1-`date --iso-8601`.sql
sleep 5
# Client 2 Backup
mysqldump --opt -Q -u username -ppassword dbname > /path/to/your/backups/


The format for the output file is just the linux date call, so this:

sitedata-`date --iso-8601`.tar.gz

Makes a file called sitedata-2008-02-24.tar.gz. In the same vein, the dtabase backups are named things like sevenstring-2008-02-24.sql, etc, etc, so that the filenames ARE the dates they are created. :) You can change 'sitedata' to whatever you want to call it.

Short version: Make textfile. Stick commands in, copy it to /etc/cron.daily (or weekly/monthly). So when I am about to install a plugin, I just run the script manually:

sh /etc/cron.weekly/backup.sh

And it does a backup stamped with today's date that I can restore from if and when I screw something up. :D

Boofo
02-24-2008, 07:55 PM
Ok, now I'm more confused than I was before. LOL

Dismounted
02-25-2008, 04:04 AM
They are bash commands you do from the command line. :) It needs SSH access into the server.

Boofo
02-25-2008, 12:48 PM
Which a lot of us do not have.

Thank for the explanation, Dismounted. ;)

snakes1100
02-25-2008, 01:41 PM
The script is already on the server if its a cron, so you dont need ssh access.

If your host panel, ie... cpanel & numerous other host panels possess the ability to setup cron based bash scripts.

Dismounted
02-26-2008, 04:46 AM
Also, I think it's time for this response :p:

The only reliable method of backing up and restoring a database is with shell access via telnet or ssh. This is because backing up with a PHP script like that in the Admin CP or phpMyAdmin can result in PHP timeouts errors and an incomplete backup file. Please see the instructions here:

Backup:
http://www.vbulletin.com/docs/html/maintenance_ssh_backup

Restore:
http://www.vbulletin.com/docs/html/maintenance_ssh_restore

P.S. If you don't have shell access, some people have also reported success with these scripts:

MySQLDumper:
http://www.mysqldumper.de/en/index.php

MySQLHotxcopy:
http://www.vbulletin.com/forum/showthread.php?t=134821&highlight=mysqlhotcopy

Bigdump:
http://www.ozerov.de/bigdump.php

SEOvB
02-26-2008, 04:55 AM
Good advice, i see all the time on forums i frequent how a host will crash, and people are irate because they didn't take 5 seconds out of their day to do a backup.

Its not the hosting providers responsibility to do reliable backups, its yours!

NeuroLancer
02-26-2008, 09:46 AM
Thanks to all those who have helped in this thread, I just finished backing up now :)

Its not the hosting providers responsibility to do reliable backups, its yours!

IMO if there were 10 vBulletin commandments, that would be in the top 3 i'm sure ;)