Backing Up - How to do it..!

Status
Not open for further replies.

Mikey

:mikey:
Staff member
Jan 26, 2008
17,835
691
510
34
Disunited Queendom
mikeylicio.us
Well one of the more common questions I see asked here on xenfans, and also something my clients often ask me is "How do I back up my database".

In this thread I hope to provide a little mini guide which caters for most people, whether you have cPanel, or direct command line access.

With SSH access, you can simply type this into the command line:
mysqldump --opt -Q -u dbusername -p databasename > backupname.sql

xenfans-backup-ssh.png

If you don't have SSH access, but do have cPanel, you can also go to yourdomain.com/cpanel - choose the backup manager, and only choose the database backup option.

xenfans-cpanel-demo-screenie.png
xenfans-cpanel-demo-screenie-2.png

If you don't have cPanel, but have access to phpMyAdmin, you can simply load your database, dont click any tables, and click the "Export" button. Make sure every table is checked, and download as a sql file :)

xenfans-phpmyadmin-backup1.png

xenfans-phpmyadmin-backup2.png

Edit - For windows server users, check out this useful blog post; http://bobschwarz.com/batch-file-to-backup-your-windows-server-database/
 
  • Like
Reactions: 5 people

Mikey

:mikey:
Staff member
Jan 26, 2008
17,835
691
510
34
Disunited Queendom
mikeylicio.us
For the more "advanced" members, who also are no longer on shared hosting, there are a number of scripts posted in this topic which will allow you to create a daily backup cronjob, so you have no worries about data loss. For those who are on a limited space VPS or Dedicated solution though, make sure that you clear out your backups directory every so often, as databases can get big (I have around 25 db's in my MySQL server, all over 50MB each).
 
  • Like
Reactions: 1 person

South Fork

OMG Member
Mar 15, 2011
8
0
45
56
From shell, after closing the forum and other applications referencing the forum DB...

mysqldump --user=USERNAME --password=PASSWORD --quick --add-drop-table --add-locks --extended-insert --lock-tables --all DATABASE | gzip > /home/path/path/backup/DATABASE-`date -I`.gz
 
  • Like
Reactions: 1 person

Floris

I'm just me :) Hi.
Staff member
Jan 1, 2001
60,248
1,473
930
48
Netherlands
mrfloris.com
I would recommend against including the password in the shell. Shared hosting and otherwise compromises being able to cat .bash_history will disclose the password incrementing compromise on the system.
 
  • Like
Reactions: 2 people

GoMySQL

OMG Member
Apr 22, 2011
24
0
55
46
Gilbert, AZ
gomysql.com
I wrote a shell script some time ago to do most of this for me.

I've modified it a bit (it will be attached)

There are also other (far better) alternatives for backups, but they are a tad more complicated. If you'd like hot backups, you can use XtraBackup from Percona (Hover over the Software link at the top, I think).

EDIT:
Duh, forgot to attach it.
 

Attachments

  • mysql_backup.sh.txt
    2.6 KB · Views: 4
  • Like
Reactions: 1 person

trilogy33

OMG Member
What I love about XenForo (sorry slightly off topic here) is that the actual (example) db.sql is so small, with not carrying the bulky attachments by default, is that it takes a tiny amount of time even to manually run a cPanel backup.
Ideal for newbs. >>> *gives a knowing nod* :)
 

Steven Moore

OMG Member
Oct 22, 2010
1,084
0
115
43
Jefferson City, Missouri
Nice discussion here, I have always used BigDump which works for any size of sql files. I don't like doing it through SSH too much and my cPanel takes forever to backup so I use that PHP script and its secure just be sure to password protect the directory so no one else can steal your databases.
 

Floris

I'm just me :) Hi.
Staff member
Jan 1, 2001
60,248
1,473
930
48
Netherlands
mrfloris.com
If you have a shell and you type commands in the bash shell, .. like

cd
cd backups
./back.sh --pass=something --database=somethingelse
cd
ls -all

then you can log out, and log back in .. and type:

cd
cat .bash_history |grep "pass"

and the line from back.sh where you manually typed in the pass , will come back, disclosing it.
 
Status
Not open for further replies.