Backup: Difference between revisions From Online Manual

Jump to: navigation, search
(→‎FTP BINARY file transfer mode prevents file damage: UTF-8 "may be" damaged (depends on whether any non-backwards-compatible characters are in the files, of course))
No edit summary
 
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{TOCright}}
{{TOCright}}
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?
It is essential to back up your forum. If your database gets corrupted you will lose everything. Having a backup means that you have a previous version of your database to fall back on should your forum be hacked, or should you make changes to it which you subsequently wish to revert.


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 toolUsually, 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.
SMF's Admin section has a built-in database backup function. '''Do not use it'''! It does work in some cases, but not in others, so it should not be used, unless you have no other way to acquire the backup of the database.


==Backing up your database==
==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.
When you bought your domain, your host will have given you details on how to access your site's cPanel®, or something similar. You can access this to back up your database.  Alternatively, you can also back up your database using ''phpMyAdmin''.


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®===
#Look for the section labelled "Files" and click on "Backups".
#On the new page that opens, you will see "Download a MySQL Database Backup".
#Under that, click on the name of your database and a requester will open, which will allow you to choose where that backup will be downloaded to.


===Backing up your database with cPanel®===
===Backing up your Database with phpMyAdmin===
If your web host uses cPanel, here's the quickest way to backup your entire database.
Again, you will need to access your site's cPanel.


#Firstly, look for the section labelled "Files" and click on (You guessed it) "Backups".
#Look for the section labelled "Databases".
#In the new page that opens, you'll see "Download a MySQL Database Backup".
#Under that heading, you will find "phpMyAdmin".
#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.
#Click on this, and then follow the steps below. '''Warning: Do not click on any options other than those outlined below, unless you really know what you are doing!'''
#Look at the left-hand pane and you will see the name(s) of your databases.
#Click on one of them and you will see some tabs along the top.
#Click ''Export''.
#On the next page, find "View dump (schema) of database", and you will see "Export".
#Just below that, click "Select all".
#At the bottom of the page, ensure that "Save as file" is checked.
#Finally, click "Go".


It really is as simple as that!
===General Notes===
<br/>So, there really is no excuse for not backing up, OK?
Once you have your backup, you should verify whether it works. The best way is to restore it to a second '''empty''' database. '''This is an important step'''. If for any reason the backup fails you can repeat the procedure immediately to ensure that have a working database in case you need it. 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.


===Backing up your database with phpMyAdmin===
If you cannot restore the database, you should verify that the ''.sql'' file you have obtained has proper SQL syntax and commands inside it (to <code>CREATE</code> your '''tables''' and <code>INSERT</code> data into them, it may also <code>DROP</code> old tables before creating new ones). Make sure it it ''looks complete'' (<code>CREATE</code> and <code>INSERT</code> for all your SMF tables), before assuming that it is 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 is in the backup file).  
Start at your website's administration panel
#Look for the section labeled "Databases".
#Under that heading, you'll find "phpMyAdmin". Click on it
#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.
# 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.
#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.
#You'll see some tabs, along the top. The one you want is labeled "Export". Click it.
# This will take you to a page called "Exporting databases from the current server"
# Under '''Format''', choose SQL. Under '''Export Method''', choose "Custom".
# 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
#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. 
If you used phpMyAdmin it may end with:
<code>/*!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 */;</code>


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
Save a copy of the backup some place safe. Your web host server '''is not''' a safe place.
<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>


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.
You do not 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.


==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===
If you have used phpMyAdmin to backup your database, you'll remember how to get started.
To restore your backed-up database, you do exactly the same as to back up, except that instead of clicking "Export", you click "Import". You then navigate to your backup file by clicking  "Choose" under "Location of the text file".
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.
 
# From the tab bar, choose the '''Import''' tab.
Please be aware that if you have large databases, it may be not possible to back up using phpMyAdmin, as phpMyAdmin has some file size limits.
# Under '''Location of the text file''', click Choose, and navigate to the .sql file you want to restore.
 
# 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.
===General Notes===
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.
 
Know how to browse through the original and restored databases in phpMyAdmin to check 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. Your host may be able to tell you how to suspend or increase the process time limit. There are utilities out there to split up the restore task into smaller pieces, so that you will not exceed time limits.
 
Depending on your host's configuration, MySQL default collation may differ from the one you need. Be sure to change the newly-created database to the appropriate collation, for example, UTF-8, before starting an import (restore).
 
phpMyAdmin needs to be told the type of encoding the .sql file(s) uses when you do the import. If your backup is, for example, 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. This will make an horrendous mess of your database.
 
If you need to rerun part of an import, be careful not to import the same data twice. If you are lucky, the process will die with a duplicate key error. This is why it is generally a good idea to '''drop''' and '''create''' the tables so that they are guaranteed to be 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.
You can open your FTP client and use it to download everything to your hard disk, or you can use your site's cPanel (or whatever your host uses).


One simple way to do this is to use your FTP client and download a bunch of files at one time to your desktop. Then, you can create a zip file and store that in a safe place. This can take a long time, because you are transferring a long list of uncompressed files.  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.
#Go to cPanel, look for the section labelled "Files" and click "Backups".
#In the new page that opens, you will see "Download a Home Directory Backup".
#Just below that, click the "Home Directory" button.
#You will get a requester which allows you to choose where the backup is saved.


A quicker way to do this is to user your site's administration panel.  Usually, they provide a way to manage files. 
This will save your whole site, so this can be a long process, especially if you have a lot of files on your site.
#Put your forum in maintenance mode
#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.
#* Choose a compressed file type to save on storage space (.zip, .tar.gz, or .tgz, depending on what you can read from your desktop)
# Store that file in a safe place.
#Remember to take your forum out of maintenance mode.
# Double check your files, especially image files, to make sure they were not damaged -- especially images, pdfs, and other non-ASCII documents.


This will save your whole site. So, be aware, of course, that this can take a LONG time to do. 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.
===General Notes===
Your control panel may have an option to pack and compress all of your files into one file (.tar.gz; .tgz; .zip,). Consider using this, as it can greatly reduce file transfer time and leave you with only one large file to worry about.
 
The larger the file, the greater the risk corrupted data, such as transmission errors, will be present. If your site contains a lot of attachments this, therefore, may not be the best choice. If you are only going to keep the file for backup, rather than to work with its individual files on your PC, this can be a good choice. If you plan to look at or edit files on your PC, however, you may want to transfer them as individual files.
 
Most FTP clients can transfer an arbitrary collection of files and directories 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.
 
For very large databases compression (.zip) may be wise, clearing all logs prior to backing-up, as well as splitting up the tables you are saving to file. When you are opting tables within phpmyadmin it is possible to highlight specific ones for each file. For example, the messages table is usually the largest, therefore, you can create two compressed database files where one contains the messages table and the other contains all remaining tables. When restoring these tables simply import the multiple files one at a time to the same database.
 
If you do not know how to use an FTP client, please see [[FTP_-_How_do_I_use_FTP]] for further information.
 
As with the database backup, do a test restore the first time you back up, and once in a while after that.
 
Store a copy of your backup somewhere other than your hosting server.  This is because even backups offered by your host may prove unreliable.


==Restoring your forum files==
==Restoring your forum files==
This can be done by using FTP to transfer the backed-up files from your hard disk to your site or by going to the same place in your site's cPanel (or whatever your host uses) that you use to back up.


If you have simply copied all the files onto your desktop, you can use FTP to copy them all back up again.
#Go to cPanel, look for the section labelled "Files" and click "Backups".
 
#In the new page that opens, you will see "Restore a Home Directory Backup".
If you have used your host's "Files" utility to create a file backup, you can use it to unpack that backup to the same location or a new one.
#Click "Choose" to navigate to your backup, then "Upload" to start the restoration.


Or you can use the "File" or "File Manager" tool your host provides.
===General Notes===
# 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.
As with database backup, practice in advance how to do a file restore to a scratch copy of the site on your server.
#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.


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


===FTP BINARY file transfer mode prevents file damage===
Spot check your restored files, especially attachments and avatars, to ensure that they have survived, especially if you use [[FTP_-_How_do_I_use_FTP#What_FTP_clients_are_available.3F|FileZilla]].
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, it will damage any image files, compressed files (.zip, .gz, .tgz, etc), non-ASCII documents (.pdf, .doc, etc), and possibly some text files that contain UTF-8 characters. You will not be able to fix these damaged files later.


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

Latest revision as of 16:29, 18 September 2014

It is essential to back up your forum. If your database gets corrupted you will lose everything. Having a backup means that you have a previous version of your database to fall back on should your forum be hacked, or should you make changes to it which you subsequently wish to revert.

SMF's Admin section has a built-in database backup function. Do not use it! It does work in some cases, but not in others, so it should not be used, unless you have no other way to acquire the backup of 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. You can access this to back up your database. Alternatively, you can also back up your database using phpMyAdmin.

Backing up your Database with cPanel®

  1. Look for the section labelled "Files" and click on "Backups".
  2. On the new page that opens, you will see "Download a MySQL Database Backup".
  3. Under that, click on the name of your database and a requester will open, which will allow you to choose where that backup will be downloaded to.

Backing up your Database with phpMyAdmin

Again, you will need to access your site's cPanel.

  1. Look for the section labelled "Databases".
  2. Under that heading, you will find "phpMyAdmin".
  3. Click on this, and then follow the steps below. Warning: Do not click on any options other than those outlined below, unless you really know what you are doing!
  4. Look at the left-hand pane and you will see the name(s) of your databases.
  5. Click on one of them and you will see some tabs along the top.
  6. Click Export.
  7. On the next page, find "View dump (schema) of database", and you will see "Export".
  8. Just below that, click "Select all".
  9. At the bottom of the page, ensure that "Save as file" is checked.
  10. Finally, click "Go".

General Notes

Once you have your backup, you should verify whether it works. The best way is to restore it to a second empty database. This is an important step. If for any reason the backup fails you can repeat the procedure immediately to ensure that have a working database in case you need it. 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.

If you cannot restore the database, you should 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 is 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 is in the backup file).

If you used phpMyAdmin it may end with: /*!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 */;

Save a copy of the backup some place safe. Your web host server is not a safe place.

You do not 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.

Restoring your database

Restoring your Database with phpMyAdmin

To restore your backed-up database, you do exactly the same as to back up, except that instead of clicking "Export", you click "Import". You then navigate to your backup file by clicking "Choose" under "Location of the text file".

Please be aware that if you have large databases, it may be not possible to back up using phpMyAdmin, as phpMyAdmin has some file size limits.

General Notes

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.

Know how to browse through the original and restored databases in phpMyAdmin to check 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. Your host may be able to tell you how to suspend or increase the process time limit. There are utilities out there to split up the restore task into smaller pieces, so that you will not exceed time limits.

Depending on your host's configuration, MySQL default collation may differ from the one you need. Be sure to change the newly-created database to the appropriate collation, for example, UTF-8, before starting an import (restore).

phpMyAdmin needs to be told the type of encoding the .sql file(s) uses when you do the import. If your backup is, for example, 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. This will make an horrendous mess of your database.

If you need to rerun part of an import, be careful not to import the same data twice. If you are lucky, the process will die with a duplicate key error. This is why it is generally a good idea to drop and create the tables so that they are guaranteed to be empty at the start.

Backing up your forum files

There are two common ways of doing this:

You can open your FTP client and use it to download everything to your hard disk, or you can use your site's cPanel (or whatever your host uses).

  1. Go to cPanel, look for the section labelled "Files" and click "Backups".
  2. In the new page that opens, you will see "Download a Home Directory Backup".
  3. Just below that, click the "Home Directory" button.
  4. You will get a requester which allows you to choose where the backup is saved.

This will save your whole site, so this can be a long process, especially if you have a lot of files on your site.

General Notes

Your control panel may have an option to pack and compress all of your files into one file (.tar.gz; .tgz; .zip,). Consider using this, as it can greatly reduce file transfer time and leave you with only one large file to worry about.

The larger the file, the greater the risk corrupted data, such as transmission errors, will be present. If your site contains a lot of attachments this, therefore, may not be the best choice. If you are only going to keep the file for backup, rather than to work with its individual files on your PC, this can be a good choice. If you plan to look at or edit files on your PC, however, you may want to transfer them as individual files.

Most FTP clients can transfer an arbitrary collection of files and directories 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.

For very large databases compression (.zip) may be wise, clearing all logs prior to backing-up, as well as splitting up the tables you are saving to file. When you are opting tables within phpmyadmin it is possible to highlight specific ones for each file. For example, the messages table is usually the largest, therefore, you can create two compressed database files where one contains the messages table and the other contains all remaining tables. When restoring these tables simply import the multiple files one at a time to the same database.

If you do not know how to use an FTP client, please see FTP_-_How_do_I_use_FTP for further information.

As with the database backup, do a test restore the first time you back up, and once in a while after that.

Store a copy of your backup somewhere other than your hosting server. This is because even backups offered by your host may prove unreliable.

Restoring your forum files

This can be done by using FTP to transfer the backed-up files from your hard disk to your site or by going to the same place in your site's cPanel (or whatever your host uses) that you use to back up.

  1. Go to cPanel, look for the section labelled "Files" and click "Backups".
  2. In the new page that opens, you will see "Restore a Home Directory Backup".
  3. Click "Choose" to navigate to your backup, then "Upload" to start the restoration.

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.

Be careful if using FileZilla to transfer with automatic mode selection. It will corrupt all attachment and avatar images unless you specify binary mode, read this note for more details.

Spot check your restored files, especially attachments and avatars, to ensure that they have survived, especially if you use FileZilla.



Advertisement: