• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How to backup and restore your forum (Linux / Windows)

Jake Bunce

XenForo moderator
Staff member
#1
Jake Bunce submitted a new resource:

How to backup and restore your forum (Linux / Windows) (version 1.x) - Detailed guide for manual backups / restores.

Note that many hosts handle backups and restores automatically. You can choose to rely on your host if you want. This guide is about manual backups and restores.

Sections below:
- Linux Server Backup
- Linux Server Restore
- Windows Server Backup
- Windows Server Restore

__________

Linux Server Backup

You need to backup your database and your files. Both are equally important. You should backup both at the same time and keep them together....​
Read more about this resource...
 

Kent

Active member
#2
Code snippet to create backups, encrypt, and upload. Note: using PGP would be more secure than AES.
Take proper care with file permissions and FTP access to ensure the backups aren't accessible and nobody can read the password if saved in a file.
Hopefully the variable names make the snippet self-explanatory.

Code:
# Do something like this for the file names: (ex. webback.2012.03.23.tar.gz.aes256)
web_backup_file="/home/someuser/backups/xenforo/web/webback.`date +%Y.%m.%d`.tar.gz.aes256"
 
# Create the MySQL dump, gzip, and encrypt it all at once. Same for the website's files.
mysqldump -u $sql_user -p $sql_pass $sql_db | gzip | openssl enc -aes-256-cbc -salt -out $sql_backup_file -pass pass:$sql_backup_password
tar -zc $web_backup_directory | openssl enc -aes-256-cbc -salt -out $web_backup_file -pass pass:$web_backup_password
 
# Use CURL to upload the backups to a remote FTP
curl -T $web_backup_file ftp://$ftp_host --user $ftp_user:$ftp_pass
 
# Decrypt and decompress the web backup (use gunzip/gzip - d for the SQL backup)
openssl enc -aes-256-cbc -d -salt -in $web_backup_file -pass pass:$web_backup_password | tar -zx
The rest is addressed in Jake's tutorial.
 

TheBigK

Well-known member
#4
I want a guide / add-on to backup my server every night to Amazon S3 and maintain 5 copies of it at any point in time.
 

Jake Bunce

XenForo moderator
Staff member
#5
it display a error on my domain after i restore the files (you don't have necessary permissions to access this page)
Is it a server error or a XenForo error? Can you post the URL?

I want a guide / add-on to backup my server every night to Amazon S3 and maintain 5 copies of it at any point in time.
You need a cron job. That would be setup on the server separate from XenForo.
 

dangonay

Active member
#7
I just did this and things went pretty well, except for one problem.

I have Shell access, but not everything was working (couldn't do database dump). I didn't want to waste time waiting to talk to tech support (stubborn) so I tried it with phpmyadmin doing a database export. The database backup worked, but the restore to the new server didn't work - I get an error 1044 since my new database has a different name from the original database.

I had to do another export without compression so I get a text file. Opened the file (had to get an editor that would open very large files) and close to the beginning is a SQL command CREATE to make the database and a USE command to use it. I removed the CREATE command altogether since I had already created my database manually and I changed the database in the USE command to my new database name.

Tried the import and it worked perfectly.

Everything else in Jake's instructions went fine.
 

ForestForTrees

Well-known member
#8
Thanks for this great tutorial. What is the lonely hyphen for in the following line? I am used to hyphens having specific letters or words after them to specify an option.
Code:
tar -cf - /PATH/TO/backup.sql /PATH/TO/FORUMDIR/ | gzip -c > /PATH/TO/backup.tar.gz
 

ForestForTrees

Well-known member
#9
For any Linux newbies following along, you may be more likely to do regular backups if you automate the process. The following very basic tutorial may be helpful for learning the basics of how to do this: http://www.linfo.org/create_shell_1.html

Note that it probably isn't worth putting the restore process in a script. Another program, chron, may be worth investigating if you want the backups to happen completely automatically.
 
Last edited:

Jake Bunce

XenForo moderator
Staff member
#10
Thanks for this great tutorial. What is the lonely hyphen for in the following line? I am used to hyphens having specific letters or words after them to specify an option.
Code:
tar -cf - /PATH/TO/backup.sql /PATH/TO/FORUMDIR/ | gzip -c > /PATH/TO/backup.tar.gz
The lonely hyphen is used instead of providing a file name for the tarball. That causes tar to use standard out which is then piped to gzip.
 

ForestForTrees

Well-known member
#11
Many thanks, Jake. It's nice to know what the command is doing.

Once a mysqldump has been made using the code above, is it possible to import it using the MySQL command line client. I'm trying to set up a local development environment and I've got MySQL installed as part of Zend Server, Free edition (Kier recommended it highly in a video).
 

Moddis

Active member
#13
Nice tips. I did run into a few problems when trying it though.

First when trying the mysql dump as:

mysqldump --opt -uforum_login -ppassword forum_name > /home/forum/forum_db.sql

Got this error:

mysqldump: Got error: 1045: Access denied for user 'forum_name'@'localhost' (using password: YES) when trying to connect

So i tried putting a space after -u and -p like so:

mysqldump --opt -u forum_login -p password forum_name > /home/forum/forum_db.sql

Then I got this error:

mysqldump: Got error: 1044: Access denied for user 'forum_name'@'localhost' to database 'Last5CharactrersOfPassword' when selecting the database

This finally worked but then it prompted me for password before continuing:

mysqldump --opt -u forum_login -p forum_name > /home/forum/forum_db.sql



As for the files backup "tar -cf - /PATH/TO/backup.sql /PATH/TO/FORUMDIR/ | gzip -c > /PATH/TO/backup.tar.gz"

I got this error close to the end of the process:

tar: Removing leading `/' from member names
tar: /home/forum/public_html/internal_data/temp/xmg22opon: Cannot open: Permi ssion denied
tar: Exiting with failure status due to previous errors

Is it because the owner of the file is "nobody" and im logged in with a different user?
 

Jake Bunce

XenForo moderator
Staff member
#14
...

As for the files backup "tar -cf - /PATH/TO/backup.sql /PATH/TO/FORUMDIR/ | gzip -c > /PATH/TO/backup.tar.gz"

I got this error close to the end of the process:

tar: Removing leading `/' from member names
tar: /home/forum/public_html/internal_data/temp/xmg22opon: Cannot open: Permi ssion denied
tar: Exiting with failure status due to previous errors

Is it because the owner of the file is "nobody" and im logged in with a different user?
Yep, the second error is due to permissions. That just means those files aren't included in the tar, but it probably completed despite that.
 

Moddis

Active member
#15
Yep, the second error is due to permissions. That just means those files aren't included in the tar, but it probably completed despite that.
Thanks. Just manually copied all files via ftp and compared them to the tar. The only thing that was missing from the tar was that one file so its all good.
 
#16
Jake Bunce submitted a new resource:

How to backup and restore your forum (Linux / Windows) (version 1.x) - Detailed guide for manual backups / restores.



Read more about this resource...
This is going to sound like a very specific or even trivial question, but could I use cPanel to back up my forum files instead of the methods you've listed?

For example, I see you recommend using shell access, phpmyadmin, and direct backing up, but what about backing up using cPanel? Is this not enough or is this inefficient?
 

Brogan

XenForo moderator
Staff member
#17
Yes, you can use cPanel, FTP, phpMyAdmin or whatever method you prefer to backup.

Note the caveat with those methods though; namely that backups may be incomplete.
 
#18
Yes, you can use cPanel, FTP, phpMyAdmin or whatever method you prefer to backup.

Note the caveat with those methods though; namely that backups may be incomplete.
Ah okay. I wasn't aware those backups could be incomplete. I spoke to my server host's customer service sometime ago and specifically asked them if everything would be backed up using cPanel. The person assured me that it would be and if my forum was ever to be wiped out, the cPanel back up could restore it entirely. But I don't think it hurts to learn about shell access to be sure.
 
#19
I want to upgrade to 1.3.2. However, I'm new to shell access and I'm running into errors already. If someone could patiently guide me through backing up via shell access, it would be very helpful.

I made a local test site and I'm trying to back that up using shell access first before messing around with SSH and my live site.

I use xampp, not putty.

I'm going to give some example info that's in my library/config.php file (it's not the actual info) for my test site.

host: localhost
port: 0001
username: alpha
dbname: beta

There is no password

I created a separate database to put my backup in. This is called omega.

This is what my code looks like:

mysqldump --opt -uALPHA BETA > /PATH/omega.sql

I removed the -pPASSWORD part since there is none. Also I'm a bit confused about the PATH/TO part. What kind of example would go there?

In any case, xampp said the path can't be specified.

Thank you.
 
#20
Okay, nevermind the above. I've figured it out (noob problem).

Now I am so close to backing up the files but xampp keeps telling me that the 'tar is not recognized as an internal or external command, operable program or batch file."

Is there any reason for this?