User:Irisado From Online Manual
It is essential to backup 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.
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 backup your database. Alternatively, you can also backup your database using phpMyAdmin.
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 phpMyAdmin
Again, you will need to access your site's cPanel.
- Look for the section labelled "Databases".
- Under that heading, you will find "phpMyAdmin".
- 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".
- 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.
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.
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.
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
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 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 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".
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.
- 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
There are two common ways of doing this.
Firstly, you can open your FTP client and use it to download everything to your hard disk.
The other way is to use your site's cPanel (Or whatever your host uses).
- Go to cPanel, look for the section labeled "Files" and click on "Backups".
- In the new page that opens, you'll see "Download a Home Directory Backup".
- Just below that, click on the "Home Directory" button.
- You'll get a requester, so that you can choose where the backup's saved to and you're away!
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.
- 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.
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.
- 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 - with most forums the messages table will be the largest therefore one can create two compressed db files whereas one contains the messages table and the other contains all other tables. When restoring these tables simply import the multiple files one at a time to the same database.
- 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
Again, this can be done by using FTP to transfer the backed-up files from your hard disk to your site.
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.
- 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.
- 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.
- 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, that they survived the round trip, especially if you use FileZilla.