1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

How to backup and restore your forum

Discussion in 'Tips and Guides [Archive]' started by Jake Bunce, Oct 27, 2010.

  1. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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.



    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.

    Backup Using Shell Access

    I highly recommend using a shell connection to make a backup. Sometimes you have to ask your host to enable shell access. You also need a shell client to make the actual connection. Putty is a popular shell client.

    1) Backing up the database.

    Here is the shell command for backing up your database. You need to replace the CAPITALIZED portions with your own info. The database information is in your library/config.php file. I prefer to use a full server path for the location of the backup.sql file:

    mysqldump --opt -uUSERNAME -pPASSWORD DBNAME > /PATH/TO/backup.sql

    If the host is not 'localhost' then you need to specify that in the command as well:

    mysqldump --opt -hHOST -uUSERNAME -pPASSWORD DBNAME > /PATH/TO/backup.sql

    2) Backing up the files.

    With shell access you can make a compressed tarball of the files together with the database. Here is the command that I use to do this. For this command I am assuming we have already created backup.sql with the previous command. As before, you need to replace the CAPITALIZED portions with your own info:

    tar -cf - /PATH/TO/backup.sql /PATH/TO/FORUMDIR/ | gzip -c > /PATH/TO/backup.tar.gz

    Now you can download the backup.tar.gz file to your computer to have a local backup.

    Backup Using Other Means

    Without shell access it can be harder to make a proper backup. The alternative backup methods can be unreliable sometimes resulting in incomplete backups.

    1) Backing up the database.

    You can use phpmyadmin to create a database backup. Phpmyadmin is a free program that allows you to manage your database. Many hosts will preinstall this program for you. Once you are logged in to phpmyadmin you just need to select your database in the left column and then click the Export tab on the top right. Select all tables for export and click the Go button on the bottom. It will download the backup to your computer. This can take a while depending on the size of the database and the speed of your connection.

    2) Backing up the files.

    Use a FTP program to download your forum directory. This can take a long time if you have a lot of attachments on your forum.



    Linux Server Restore

    Basically you need to restore the database backup to a database on the server. Then you need to put the forum files in place. Then edit the library/config.php file to point to the database.

    Restore Using Shell Access

    Shell access is often required to restore a backup unless your backup is very small. You can ask your host to enable shell access. You also need a shell client to make the actual connection. Putty is a popular shell client.

    If you followed the shell backup instructions above then you will need to untar/unzip the backup in order to get at the forum files and database backup. I usually copy or move the tar.gz file to it's own directory and then run these commands:

    gzip -d backup.tar.gz
    tar -xf backup.tar

    Now the database backup and forum files are ready to be restored.

    1) Restoring the database.

    Here is the shell command for restoring your database. You need to replace the CAPITALIZED portions with your own info. It is best to restore to an empty database:

    mysql -uUSERNAME -pPASSWORD DBNAME < /PATH/TO/backup.sql

    If the host is not 'localhost' then you need to specify that in the command as well:

    mysql -hHOST -uUSERNAME -pPASSWORD DBNAME < /PATH/TO/backup.sql

    2) Restoring the files.

    With the forum files already on the server you just need to move them into place. Here is the command to move the directory. As before, you need to replace the CAPITALIZED portions with your own info:

    mv /PATH/TO/BACKUP/FORUMDIR/ /PATH/TO/WEBROOT/

    3) Edit the config file.

    Now you need to edit the library/config.php file to point to the database to which you restored the database backup.

    Restore Using Other Means

    Without shell access you can try using other means to restore the backup. But these other methods don't always work.

    1) Restoring the database.

    You can use phpmyadmin to restore the database. Phpmyadmin is a free program that allows you to manage your database. Many hosts will preinstall this program for you. Once you are logged in to phpmyadmin you need to select your database in the left column and then click the Import tab on the top right. Browse to your database backup file on your computer and then click Go on the bottom. This can take a while depending on the size of the database and the speed of your connection.

    2) Restoring the files.

    Use a FTP program to upload your forum directory. This can take a long time if you have a lot of attachments on your forum.

    3) Edit the config file.

    Now you need to edit the library/config.php file to point to the database to which you restored the database backup.
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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.



    Windows 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.

    Backup Using Remote Desktop

    Windows servers often come with remote desktop access (RDP) which makes backups easy. You will need a RDP client. Every Windows PC has a RDP client. If you are on Mac OS X then you can use CoRD.

    1) Backing up the database.

    Here is the command for backing up your database. This command can be run in the Windows command prompt through RDP. You need to replace the CAPITALIZED portions with your own info. The database information is in your library/config.php file. I prefer to use full paths for all locations:

    "C:\PATH\TO\MYSQL\bin\mysqldump.exe" --opt -uUSERNAME -pPASSWORD DBNAME > "C:\PATH\TO\backup.sql"

    If the host is not 'localhost' then you need to specify that in the command as well:

    "C:\PATH\TO\MYSQL\bin\mysqldump.exe" --opt -hHOST -uUSERNAME -pPASSWORD DBNAME > "C:\PATH\TO\backup.sql"

    2) Backing up the files.

    With RDP access you can simply make a copy of the forum directory using the Windows desktop environment as you would on any Windows PC. I recommend creating a zip file with both the database backup and the forum files.

    Backup Using Other Means

    Without RDP access it can be harder to make a proper backup. The alternative backup methods can be unreliable sometimes resulting in incomplete backups.

    1) Backing up the database.

    You can use phpmyadmin to create a database backup. Phpmyadmin is a free program that allows you to manage your database. Many hosts will preinstall this program for you. Once you are logged in to phpmyadmin you just need to select your database in the left column and then click the Export tab on the top right. Select all tables for export and click the Go button on the bottom. It will download the backup to your computer. This can take a while depending on the size of the database and the speed of your connection.

    2) Backing up the files.

    Use a FTP program to download your forum directory. This can take a long time if you have a lot of attachments on your forum.



    Windows Server Restore

    Basically you need to restore the database backup to a database on the server. Then you need to put the forum files in place. Then edit the library/config.php file to point to the database.

    Restore Using Remote Desktop

    Windows servers often come with remote desktop access (RDP) which makes restores easy. You will need a RDP client. Every Windows PC has a RDP client. If you are on Mac OS X then you can use CoRD.

    1) Restoring the database.

    Here is the command for restoring your database. This command can be run in the Windows command prompt through RDP. You need to replace the CAPITALIZED portions with your own info. It is best to restore to an empty database:

    "C:\PATH\TO\MYSQL\bin\mysql.exe" -uUSERNAME -pPASSWORD DBNAME < "C:\PATH\TO\backup.sql"

    If the host is not 'localhost' then you need to specify that in the command as well:

    "C:\PATH\TO\MYSQL\bin\mysql.exe" -hHOST -uUSERNAME -pPASSWORD DBNAME < "C:\PATH\TO\backup.sql"

    2) Restoring the files.

    With RDP access you can simply copy the backup of the forum directory to the web root using the Windows desktop environment as you would on any Windows PC.

    3) Edit the config file.

    Now you need to edit the library/config.php file to point to the database to which you restored the database backup.

    Restore Using Other Means

    Without RDP access you can try using other means to restore the backup. But these other methods don't always work.

    1) Restoring the database.

    You can use phpmyadmin to restore the database. Phpmyadmin is a free program that allows you to manage your database. Many hosts will preinstall this program for you. Once you are logged in to phpmyadmin you need to select your database in the left column and then click the Import tab on the top right. Browse to your database backup file on your computer and then click Go on the bottom. This can take a while depending on the size of the database and the speed of your connection.

    2) Restoring the files.

    Use a FTP program to upload your forum directory. This can take a long time if you have a lot of attachments on your forum.

    3) Edit the config file.

    Now you need to edit the library/config.php file to point to the database to which you restored the database backup.
     
    Phil, Learner, psTubble27 and 11 others like this.
  3. Floris

    Floris Guest

    Big thumbs up to Jake :)
     
  4. anotheralias

    anotheralias Well-Known Member

    Is there any chance that the cPanel backup system is ok to use?
     
  5. CFodder

    CFodder Well-Known Member

    I just have a backup database, copy the live one over it.
     
    anotheralias likes this.
  6. anotheralias

    anotheralias Well-Known Member

    Thank you for answering, CFodder. But I have no idea what that means. I don't want to copy anything anywhere - just save the database now and again because it seems like a good idea, even though my host does nightly backups anyway.
     
  7. CFodder

    CFodder Well-Known Member

    Who do you host with? The @#^@'s I'm with only do weekly ones - if they work.
     
  8. anotheralias

    anotheralias Well-Known Member

  9. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    The CPanel backup feature works great. CPanel backups are also easy to restore on CPanel servers. And if you need to restore to a non-CPanel server then you can open up the backup file to get at the forum database and files so you can manually restore them.
     
    anotheralias likes this.
  10. anotheralias

    anotheralias Well-Known Member

    Thanks so much Jake! :)
     
  11. FreshFroot

    FreshFroot Well-Known Member

    Question here.

    I am using WAMP on Windows.

    My database is about 100-150 MB.
    I have finished with modifying it and need to get it on my live server.

    Is there anyway to backup the database without using phpymyadmin? Or do I just have to wait a really long time? I am using a P4 3.0 GHZ single core processor, 1 GB ram.

    I guess it will take 1-2 hrs to export? Or is there a faster method?

    As stated I am using WAMP with phpmyadmin.

    Thanks
     
  12. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    If you have RDP access then you can use the backup command posted above:

    "C:\PATH\TO\MYSQL\bin\mysqldump.exe" --opt -uUSERNAME -pPASSWORD DBNAME > "C:\PATH\TO\backup.sql"

    Or you can ask your host to create a backup for you.

    Phpmyadmin will probably work.

    Here is another one I have seen recommended:

    http://www.ozerov.de/bigdump.php
     
    FreshFroot likes this.
  13. FreshFroot

    FreshFroot Well-Known Member

    So that command should work on a Windows XP using WAMP PC?

    I'll have to try RDP. I don't think I used it or know much about it.

    I tried phpmyadmin, but it seemed like it would take forever. I could just hear my PC gathering all the data.

    Which is why I was wondering if there is another way to export the database as a .sql to upload to my server online and then restore.
     
  14. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Yes. You can run that command in the Windows command prompt.

    RDP gives you access to the desktop environment on the server, just like using your Windows PC.
     
    FreshFroot likes this.
  15. FreshFroot

    FreshFroot Well-Known Member

    Sounds good Jake.

    I will give it a try and see how things go.

    Thanks for the help :)

    Appreciate it.
     
  16. Ryan Kent

    Ryan Kent Well-Known Member

    Hi Jake.

    My host provides a Linux box with cPanel access. I have never used nor connected with Linux before and have made numerous backups with the cPanel "Backups" option. My XF main forums is located @ public_html\community. Today I created a development/testing installation of XF @ public_html\dev. I would like to back up my live forums and restore them to the test environment, then do some testing.

    When I make the backup I see the following text
    So my two questions would be:

    1. How to do a cPanel backup (if possible)
    2. How can I control which database is restored. Specifically I am taking my live server backup and "restoring" it to my test server.
     
  17. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    If you have shell access to the server then you can use the backup / restore commands from my first post.

    CPanel has different skins. But there should be a backup option when you login to CPanel:

    Screen shot 2011-02-25 at 11.48.39 PM.png

    Inside the backup area there is an option to both backup a database and restore a backup. You can download the backup, rename the file to specify a different database name, and then restore the backup. When you restore a database backup in CPanel it uses the name of the file as the target database.
     
    Steve F likes this.
  18. BlackMuddler

    BlackMuddler Active Member

    This is so good written and understandably - Wanted to give you alot of likes but only one - So here is one round [​IMG] instead ..
     
  19. Ryan Kent

    Ryan Kent Well-Known Member

    I have one question regarding excluding a given directory from a backup.

    I have around 15 GB of locally hosted videos, and the size will definitely grow in time. I would like to exclude the directory from backups. I will figure out another solution for this directory.

    Including this directory makes the backup process take way too long, and the size is not reasonable for downloading off-site backups.

    I have tried many variations and cannot seem to exclude this video directory. My current code is:

    tar --exclude "\/home\/terapvp\/public_html\/data\/local\/*" -cf ${HOME_DIR}/${FILES_DIR}/${THEDATE}_site.tar -C ${HOME_DIR} ${HTML_DIR}

    Any ideas as to where I am going wrong?
     
  20. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    I was able to make this work in my testing, but only when the excluded directory path contains no ending slash. Here is the command from my original post with an excluded directory specified:

    tar -cf - /PATH/TO/backup.sql /PATH/TO/FORUMDIR/ --exclude "/PATH/TO/EXCLUDEDDIR" | gzip -c > /PATH/TO/backup.tar.gz

    Notice there is no ending slash on "/PATH/TO/EXCLUDEDDIR". Try that.
     
    p4guru likes this.

Share This Page