Backup: Difference between revisions From Online Manual

Jump to: navigation, search
mNo edit summary
(updated phpMyAdmin description (they have reordered some of the options). generalized the "cpanel file backup" instructions because not all web hosts use this utility.)
Line 1: Line 1:
{{TOCright}}
{{TOCright}}
Backing up is the most important thing you can ever do with SMF or any website. Don't let anyone else tell you differently. If something goes wrong, you may well be able to fix it. If you can not, maybe somebody else can. But what happens if nobody '''can''' help you? Databases can extremely difficult to repair.
Backing up is the most important thing you can ever do with SMF or any website. If something goes wrong, you may be able to fix it, or someone else may be able to fix it. But if nobody can fix it, what happens?  Bye-bye forum. Bye-bye members. Bye-bye posts. Now, you REALLY do not want that to happen, do you? Of course not. So, what to do?


Bye-bye forum. Bye-bye members. Bye-bye posts.
First -- the database.  While SMF 1.1.x and SMF 2.0.x had backup tools, these were not always reliable. You'll want a fast, reliable database backup tool.  Usually, your web host will provide you one that works with your database. Second -- the files. While you can always re-install SMF and mods, you cannot get back attachments or any gallery mod uploads.  You'll want to back up these files also.


Now, you REALLY do not want that to happen, do you? Of course not. So, what to do?
==Backing up your database==
First, put your forum in maintenance mode.  You don't want your members trying to add new posts to the database while you are trying to back things up.


You may have noticed that there's a facility in SMF's "Forum Maintenance" section, to backup your database. This works great -- for smaller forums.  For larger forums, and on some shared hosting systems, it only manages to get part way through the job.  So, we'll ignore it.  Also, though, what about the files on your site? And what about restoring the backups?
Your web host will provide you tools for backing up the database.  Poke around your account administration panel.  You may find a link to "backup database" or else you'll find tools like phpMyAdmin or phpPgAdmin to work with your specific database. If you do not have access to your site's control panel, just search the internet for some other tools you can use for backups.
 
Firstly, let's deal with the database.
==Backing up your database==
When you bought your domain, your host will have given you details on how to access your site's cPanel®, or something similar.
<br>There, you'll be able to access something called "phpmyadmin".
<br>Now, of course, different hosts will have different ways of accessing that. For the sake of this article, I'm going to give the means of accessing it via cPanel. Other hosts may be different. But, they'll be pretty similar.


===Backing up your database with cPanel®===
===Backing up your database with cPanel®===
If your web host uses cPanel, here's the quickest way to backup your entire database.


#Firstly, look for the section labelled "Files" and click on (You guessed it) "Backups".
#Firstly, look for the section labelled "Files" and click on (You guessed it) "Backups".
Line 21: Line 17:


It really is as simple as that!
It really is as simple as that!
<br>So, there really is no excuse for not backing up, OK?
<br/>So, there really is no excuse for not backing up, OK?
 
The second way, is to use phpMyAdmin.


===Backing up your database with phpMyAdmin===
===Backing up your database with phpMyAdmin===
Again, you'll need your site's cPanel.
Start at your website's administration panel
 
#Look for the section labeled "Databases".
#Look for the section labeled "Databases".
#Under that heading, you'll find "phpMyAdmin".
#Under that heading, you'll find "phpMyAdmin". Click on it
#If you click that, you'll see a page that might, at first, seem somewhat scary.
#Depending on your web host, you might have to first choose a database before logging in, or else you'll have to log in first and then choose a database.
#It IS. Be careful what you do, there, because you can SERIOUSLY break things.
# Once you are logged in (this might happen automatically) and have picked a database, you will see you have lots of options.  This might seem a little scary.
#Look at the left-hand pane and you'll see the name(s) of your databases.
#It '''is'''. From here, you can do anything to your database you want to do. Just stick to the script and you'll be OK.
#Click on one of them and you'll taken to another scary page.
#You'll see some tabs, along the top. The one you want is labeled "Export". Click it.
#On there, you'll see some tabs, along the top. The one you want is labeled "Export".
# This will take you to a page called "Exporting databases from the current server"
#When you click on that, you'll get yet another page.
# Under '''Format''', choose SQL.  Under '''Export Method''', choose "Custom".
#Under "View dump (schema) of database", you'll see "Export".
# That opens up a whole lot of options, most of which you don't need to change.
#Just below that, click "Select all".
#* Under "Select Database" make sure the database with your SMF tables in it is selected.
#At the bottom of the page, ensure that "Save as file" is checked.
#*At '''Character set of the file" choose the character set of your database.  You can find this by checking inside SMF.
#* Make sure "save output to a file" is ticked.
#* Make sure "structure and data" is checked
#* tick the box next to "Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT statement" and tick that box
#Then, click "Go".
#Then, click "Go".
#Save a copy of the backup some place safe. Your web host server '''is not''' a safe place -- if it is damaged, you lose both your forum AND everything you need to recreate your forum.
# Remember to take your forum out of maintenance mode.
After you finish the backup, VERIFY your backup.  Restore it to a second, empty database.  If for some reason there is something wrong with this backup, you want to know NOW so you can repeat the procedure and get it right.  If you cannot get it right, talk to your host about how to solve the problem. 


The rest, I think you'll be familiar with.
You don't need to go over your backup with a fine-toothed come every single time, but you should do this the first time, whenever you change how you do things, and just every once in a while.  At the very least, have a look at the .sql file.  It should end with something like
<code>/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;<br>/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;<br>/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;</code>


===General Notes===
If you have a very large forum, the phpMyAdmin backup method might not work because of file size limits. If this happens to you, talk to your host about other tools you can use.
#SMF's Admin section has a built-in database backup function. It works in many cases, but also fails in many cases, so we recommend that you '''do not use it''' unless you have no other way to acquire the backup of the database.
#Once you have your backup, you should verify if it works or not. The best way is to restore it to a second, empty, database.<br>This is an important step because if for any reason the backup fails you can repeat the procedure immediately and be sure to have a working database in the case you would need it.<br><br>Backups may fail for several reasons, if after repeating the procedure you still are not able to obtain a working backup, please contact your host in order to identify and solve the problem causing the backup to fail.<br><br>If you cannot restore the database, should at least verify that the ''.sql'' file you have obtained has proper SQL syntax and commands inside it (to CREATE your TABLEs and INSERT data into them, it may also DROP old tables before creating new ones). Make sure it it ''looks complete'' (CREATE and INSERT for all your SMF tables), before assuming that it's a good backup. Spot check a few tables to see if all their data is in the backup (note that the order of records may differ between the database "browse" display and what's in the backup file). If you used SMF's admin panel, make sure the file ends with <br><code>-- Done</code><br>if you used phpMyAdmin it may end with <br><code>/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;<br>/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;<br>/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;</code>
#Save a copy of the backup some place safe. Your web host server '''is not''' a safe palce.
#You don't have to go over your backup with a fine-toothed comb ''every'' time, but you should do so the first time, whenever you make a change to your backup method, and just once in a while (for good measure).


==Restoring your database==
==Restoring your database==
Once you have a .sql file, there are a number of tools you can use to restore it.


===Restoring your database with phpMyAdmin===
===Restoring your database with phpMyAdmin===
To restore your backed-up database, you do exactly the same as to backup, except that instead of clicking "Export", you need the "Import" tab and you navigate to your backup file, by clicking on "Choose", under "Location of the text file".
If you have used phpMyAdmin to backup your database, you'll remember how to get started.
 
If you have followed the instructions above, restoring the database will first wipe out everything already on the database. You'll be back at the point you were at the moment you did the backup.
Please, be aware, though, that if you have large databases, it may be not possible to backup using phpMyAdmin, as phpMyAdmin has some file size limits.
# From the tab bar, choose the '''Import''' tab.
 
# Under '''Location of the text file''', click Choose, and navigate to the .sql file you want to restore.
===General Notes===
# If you run into any problems during the restore, this may be because of timeout limits your host has set. Do not panic. Talk to your host about what you can do . Look into utilities that can split up the import task into smaller pieces so you won't exceed time limits.
#SMF does not include any utility for reloading (restoring) the database.
#Learn how to do a database restore ''ahead of time'', and practice it at least once (with a ''scratch'' copy of the database), so you won't be in a blind panic when you have to do it for real.
#Know how to browse through the original and restored databases (in phpMyAdmin) to eyeball them and get a comfortable feeling that everything is there (all records in all tables). Note that there is no guarantee that records will appear in the same order in the original database, the backup, and the new database.
#Some hosts have process time limits that may prevent you from running your restore (via phpMyAdmin) to completion. Not to panic. You may be able to find out from your host how to suspend or increase the process time limit. There are utilities out there to split up the restore (import) task into smaller pieces so you won't exceed time limits.
#Depending on your host configuration, MySQL default collation may differ from the one you need, be sure to change the newly-created database to the appropriate collation (e.g., UTF-8) before starting an import (restore).
#phpMyAdmin needs to be told what encoding the .sql file(s) are in when you do the import. If your backup is, say, UTF-8, you need to tell phpMyAdmin that, or it will assume the file is Latin-1 and will translate all the text from Latin-1 to whatever encoding your new database is in (say, UTF-8). This will make a horrendous mess of your database.
#Especially if you need to rerun part of an import, be careful not to import the same data twice. If you're lucky, the process will die with a duplicate key error. This is why it's generally good to DROP and CREATE the tables so that they're guaranteed empty at the start.


==Backing up your forum files==
==Backing up your forum files==


There are two common ways of doing this.
There are two common ways of doing this.  At some point, you are probably going to need to use [[FTP_-_How_do_I_use_FTP|FTP]] to transfer files, so get comfortable with it.


Firstly, you can open your FTP client and use it to download everything to your hard disk.
One simple way to do this is to use your FTP client and download everything to your hard disk (ftp can transfer multiple files at one time; learn how your client does this).  Then, you can create a zip file and store it in a safe place.  This can take a long time, because you are transferring files BEFORE you compress them.  And be very careful that you use BINARY mode to transfer anything that is not save to transfer in ASCII mode.  Use your FTP client's "Binary" setting.


The other way is to use your site's cPanel (Or whatever your host uses).
A quicker way to do this is to user your site's administration panel.  Usually, they provide a way to manage files.
 
#Put your forum in maintenance mode
#Go to cPanel, look for the section labeled "Files" and click on "Backups".
#Look for something like "Files" or "File Manager"
#In the new page that opens, you'll see "Download a Home Directory Backup".
#Look for a link to "Backups" or "archive". Click on or use a tick-box next to the directory you want to back up
#Just below that, click on the "Home Directory" button.
# Follow the instructions to create a file. 
#You'll get a requester, so that you can choose where the backup's saved to and you're away!
#* Choose a compressed file (.zip, .tar.gz, or .tgz, depending on what you can read from your desktop)
#* The utility might ask you immediately for a location on your PC.  Choose where you want the file to go.
#* The utility might instead create a file on the server. After it is done, use FTP to bring it to your PC.
#Store that file in a safe place.  If your desktop PC goes kapluie, what then?
# Double check your files, especially image files, to make sure they were not corrupted.
#Remember to take your forum out of maintenance mode.


This will save your whole site. So, be aware, of course, that this can take a LONG time to do, especially if you have a lot of files on your site.
This will save your whole site. So, be aware, of course, that this can take a LONG time to do, especially if you have a lot of files on your site.


===General Notes===
If you have a lot of big files on your site, this process might fail. You might need to archive just a part of your site at a time -- one or two directories at a time. If you cannot get this to work, talk to your host.
#Your control panel may have an option to pack (and compress) all your files into one file (.tar.gz, .tgz, .zip, etc.). Consider using this, as it can greatly reduce file transfer time and leave you with only one (large) file to worry about.<br>Of course the bigger the file, the bigger the risk corrupted data will be present (for example transmission errors), so if your site contains a lot of attachments this may not be the best choice. If you're only going to hold on to the file for backup, and not work with its individual files on your PC, this can be a good choice. On the other hand, if you plan to look at or edit files on your PC, you may want to transfer them as individual files.
#Most FTP clients can transfer an arbitrary collection of files and directories (folders) in one operation (such as the entire site at once). There is no need to transfer one file at a time. Some control panel File Managers can do this too.
#If you don't know how to use an FTP client, please read carefully the page [[FTP_-_How_do_I_use_FTP]], in particular the note about FileZilla.
#As with the database backup, do a test restore the first time you back up, and once in a while after that. You want to know that you're doing it right and can do a restore when (not if) it comes time to do it for real.
#Store a copy of your backup somewhere other than your hosting server. Even the best hosts have been known to discover that their own server backups are no good!


==Restoring your forum files==
==Restoring your forum files==


Again, this can be done by using FTP to transfer the backed-up files from your hard disk to your site.
If you have simply copied all the files onto your desktop, you can use FTP to copy them all back up again.


The other way is to go to the same place in your site's cPanel (Or whatever your host uses) that you use to backup.
Or you can use the "File" or "File Manager" tool your host provides.
# Make sure you want to totally replace your files.  You are about to go back in time to the moment you backed up these files.
# Click around. Look for Backups, or an option to Import or Upload files.
#* It might upload the file directly from your hard drive
#* Or you might have to use FTP to copy the compressed file to your website
# Look for an option to Restore or Uncompress a file
# Follow the instructions to get that file onto your web server and uncompressed.


#Go to cPanel, look for the section labeled "Files" and click on "Backups".
#In the new page that opens, you'll see "Restore a Home Directory Backup". Click "Choose" to navigate to your backup, then "Upload" to start the restoration.


===General Notes===
===General Notes===
#As with database backup, practice in advance how to do a file restore (to a scratch copy of the site on your server). A panic situation is not a good time to be learning such things.
# When you use FTP, make sure you use the correct method for transferring files. "Binary" mode is the safest should be OK. If you accidentally transfer image files in "ASCII" mode, or your FTP client's "Automatic" mode does not correctly choose binary when it needs to, you will corrupt all your image files, as well as any files that contain UTF-8 characters. You will not be able to fix these files.
#Be careful if using FileZilla to transfer with automatic mode selection. It will corrupt all attachment and avatar images unless you specify '''binary''' mode, [[FTP_-_How_do_I_use_FTP#What_FTP_clients_are_available.3F|read this note for more details]].
#Spot check your restored files, especially attachments and avatars, that they survived the round trip, especially if you use [[FTP_-_How_do_I_use_FTP#What_FTP_clients_are_available.3F|FileZilla]].


[[Category:Installing and Upgrading]]
[[Category:Installing and Upgrading]]
[[Category:FAQ]]
[[Category:FAQ]]
[[Category:BFG]]
[[Category:BFG]]

Revision as of 14:23, 9 April 2014

Backing up is the most important thing you can ever do with SMF or any website. If something goes wrong, you may be able to fix it, or someone else may be able to fix it. But if nobody can fix it, what happens? Bye-bye forum. Bye-bye members. Bye-bye posts. Now, you REALLY do not want that to happen, do you? Of course not. So, what to do?

First -- the database. While SMF 1.1.x and SMF 2.0.x had backup tools, these were not always reliable. You'll want a fast, reliable database backup tool. Usually, your web host will provide you one that works with your database. Second -- the files. While you can always re-install SMF and mods, you cannot get back attachments or any gallery mod uploads. You'll want to back up these files also.

Backing up your database

First, put your forum in maintenance mode. You don't want your members trying to add new posts to the database while you are trying to back things up.

Your web host will provide you tools for backing up the database. Poke around your account administration panel. You may find a link to "backup database" or else you'll find tools like phpMyAdmin or phpPgAdmin to work with your specific database. If you do not have access to your site's control panel, just search the internet for some other tools you can use for backups.

Backing up your database with cPanel®

If your web host uses cPanel, here's the quickest way to backup your entire database.

  1. Firstly, look for the section labelled "Files" and click on (You guessed it) "Backups".
  2. In the new page that opens, you'll see "Download a MySQL Database Backup".
  3. Under that, click on the name of your database and a requester will open, so that you can choose where that backup should be downloaded to.

It really is as simple as that!
So, there really is no excuse for not backing up, OK?

Backing up your database with phpMyAdmin

Start at your website's administration panel

  1. Look for the section labeled "Databases".
  2. Under that heading, you'll find "phpMyAdmin". Click on it
  3. Depending on your web host, you might have to first choose a database before logging in, or else you'll have to log in first and then choose a database.
  4. Once you are logged in (this might happen automatically) and have picked a database, you will see you have lots of options. This might seem a little scary.
  5. It is. From here, you can do anything to your database you want to do. Just stick to the script and you'll be OK.
  6. You'll see some tabs, along the top. The one you want is labeled "Export". Click it.
  7. This will take you to a page called "Exporting databases from the current server"
  8. Under Format, choose SQL. Under Export Method, choose "Custom".
  9. That opens up a whole lot of options, most of which you don't need to change.
    • Under "Select Database" make sure the database with your SMF tables in it is selected.
    • At Character set of the file" choose the character set of your database. You can find this by checking inside SMF.
    • Make sure "save output to a file" is ticked.
    • Make sure "structure and data" is checked
    • tick the box next to "Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT statement" and tick that box
  10. Then, click "Go".
  11. Save a copy of the backup some place safe. Your web host server is not a safe place -- if it is damaged, you lose both your forum AND everything you need to recreate your forum.
  12. Remember to take your forum out of maintenance mode.

After you finish the backup, VERIFY your backup. Restore it to a second, empty database. If for some reason there is something wrong with this backup, you want to know NOW so you can repeat the procedure and get it right. If you cannot get it right, talk to your host about how to solve the problem.

You don't need to go over your backup with a fine-toothed come every single time, but you should do this the first time, whenever you change how you do things, and just every once in a while. At the very least, have a look at the .sql file. It should end with something like /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

If you have a very large forum, the phpMyAdmin backup method might not work because of file size limits. If this happens to you, talk to your host about other tools you can use.

Restoring your database

Once you have a .sql file, there are a number of tools you can use to restore it.

Restoring your database with phpMyAdmin

If you have used phpMyAdmin to backup your database, you'll remember how to get started. If you have followed the instructions above, restoring the database will first wipe out everything already on the database. You'll be back at the point you were at the moment you did the backup.

  1. From the tab bar, choose the Import tab.
  2. Under Location of the text file, click Choose, and navigate to the .sql file you want to restore.
  3. If you run into any problems during the restore, this may be because of timeout limits your host has set. Do not panic. Talk to your host about what you can do . Look into utilities that can split up the import task into smaller pieces so you won't exceed time limits.

Backing up your forum files

There are two common ways of doing this. At some point, you are probably going to need to use FTP to transfer files, so get comfortable with it.

One simple way to do this is to use your FTP client and download everything to your hard disk (ftp can transfer multiple files at one time; learn how your client does this). Then, you can create a zip file and store it in a safe place. This can take a long time, because you are transferring files BEFORE you compress them. And be very careful that you use BINARY mode to transfer anything that is not save to transfer in ASCII mode. Use your FTP client's "Binary" setting.

A quicker way to do this is to user your site's administration panel. Usually, they provide a way to manage files.

  1. Put your forum in maintenance mode
  2. Look for something like "Files" or "File Manager"
  3. Look for a link to "Backups" or "archive". Click on or use a tick-box next to the directory you want to back up
  4. Follow the instructions to create a file.
    • Choose a compressed file (.zip, .tar.gz, or .tgz, depending on what you can read from your desktop)
    • The utility might ask you immediately for a location on your PC. Choose where you want the file to go.
    • The utility might instead create a file on the server. After it is done, use FTP to bring it to your PC.
  5. Store that file in a safe place. If your desktop PC goes kapluie, what then?
  6. Double check your files, especially image files, to make sure they were not corrupted.
  7. Remember to take your forum out of maintenance mode.

This will save your whole site. So, be aware, of course, that this can take a LONG time to do, especially if you have a lot of files on your site.

If you have a lot of big files on your site, this process might fail. You might need to archive just a part of your site at a time -- one or two directories at a time. If you cannot get this to work, talk to your host.

Restoring your forum files

If you have simply copied all the files onto your desktop, you can use FTP to copy them all back up again.

Or you can use the "File" or "File Manager" tool your host provides.

  1. Make sure you want to totally replace your files. You are about to go back in time to the moment you backed up these files.
  2. Click around. Look for Backups, or an option to Import or Upload files.
    • It might upload the file directly from your hard drive
    • Or you might have to use FTP to copy the compressed file to your website
  3. Look for an option to Restore or Uncompress a file
  4. Follow the instructions to get that file onto your web server and uncompressed.


General Notes

  1. When you use FTP, make sure you use the correct method for transferring files. "Binary" mode is the safest should be OK. If you accidentally transfer image files in "ASCII" mode, or your FTP client's "Automatic" mode does not correctly choose binary when it needs to, you will corrupt all your image files, as well as any files that contain UTF-8 characters. You will not be able to fix these files.


Advertisement: