Cchost/admin/System Backups

From Creative Commons
Jump to: navigation, search


Docs Home Install Upgrade Troubleshoot Customize Admins Devs Content Query Templates Commands Skins


WARNING: Saving and restoring configuration is broken in release 5.0.0 but has been fixed in the 5.0.1

Backup vs. Mirror

There are two reasons to save the state of a ccHost installation:

  1. You want a backup snapshot for disaster or other recovery. That is, you want to protect your site from yourself and other environmental calamities.
  2. You want to create a 'mirror' of your install on a different machine in order to test new home pages, write code, try out new skins and plugins, etc. Mirroring can be thought of export from the 'main' installation and import to a 'mirror' installation on another machine.

Both operations (backup and restore vs. export and import) are essentially the same set of steps with some the variations outlined below.

What to Backup/Mirror?

When considering a backup or mirror there are four distinct components to think about:

  1. User uploaded content.
  2. The database.
  3. Configuration settings.
  4. Custom files that you have added and edited.

Each of these deserve special attention and a different approach.

User Uploads

The user uploaded media content files are all under the content and contests directories. (If you don't see these directories it is because you haven't uploaded any content yet.)

You should backup the files the same way you would any directory structure: copy them somewhere else. Make sure to keep the directory tree structure exactly 'as is' because ccHost makes specific assumptions about the tree.

If you are exporting to create a mirror: the media content files are not strictly necessary. Unless you are testing the 'download' or 'stream' functionality a ccHost installation will operate at 100% fidelity even when the media content files are not present.


In order to perform the operations below you'll need to know the database name, database user name, database user name's password and the database's server that you used when you installed ccHost. If you ever forget these then just take a peek inside the file cc-config-db.php in the root of your installation.


Database

Your database holds meta information about every upload and user, plus all reviews, ratings, forum threads, etc.

The simplest (and official) way to backup a mysql database is to export the data using either the mysqldump utility from the command line or phpMyAdmin from your browser depending on which you have available.


If you have both available then it depends on how often you back up whether you want to make a simple command line script that you run very regularly or if you prefer having a visual representation of the options available for you on the screen when you perform the export.

The key difference for a mirror is that you do not export the table called cc_tbl_config.

Saving with mysqldump Command Line

To save the contents of your database:

 mysqldump --create-options --add-drop-table -u USERNAME -pPASSWORD DBNAME > mixterdump.sql

Note this is no space between the -p and the password.

If you are in a hosted or otherwise remote environment, you'll need to add the --host option to specify your database server name.

 --host=mysql.someserver.example.com

For a mirror operation add the option:

 --ignore-table=DBNAME.cc_tbl_config

Restoring with mysql Command Line

mysqldump is only good for, well, dumping. You'll use the mysql program for restoring. The syntax for that looks something like:

  mysql -u USERNAME -pPASSWORD -d DBNAME < dbname.sql

This will completely destroy your existing ccHost installation because this is a replace operation, not a merge.

Saving from phpMyAdmin

From the main phpMyAdmin screen: Select the ccHost database from the dropdown on the left.

Select the Export tab then fill out the form as follows:

  • Click 'Select All' to get the complete list of tables. (For export to another machine de-select (using control-click) cc_tbl_config.)
  • Make sure 'SQL' is selected for the output format
  • Make sure 'Structure' is checked and, under that, 'Add DROP TABLE', 'Add AUTO_INCREMENT value' and 'Enclose name and field names with backquotes'.
  • Make sure 'Data' is checked.
  • Check 'Save as file.'
  • Click Go and you should be prompted to download the dbname.sql file.

Restoring from myPhpAdmin

From the main phpMyAdmin page select your cchost database from the list on the left.

Select the Import tab.

Use the 'Import from file' option and browse for your .sql file and then click on Go.

This will completely destroy your existing ccHost installation because this is a replace operation, not a merge.

Saving Configuration

Configuration Backup

Before making extensive, experimental or otherwise scary changes to your configuration you should consider taking a snapshot of your configuration:

Browse to media/export. This will return a copy of your configuration directory to your browser.

Every browser has some kind of 'Save page' function typically found on the 'File' menu. Use that feature to save the results of the export command to a text file and then copy it to your server. For simplicity's sake, let's say you save it as snapshot1.txt in the root directory or your server installation.


The command syntax to restore a configuration is import?i=path_to_file where path_to_file is relative to the your root installation.

In our example to restore your configuration browse to import?i=snapshot1.txt

If you are recovering from a nasty page rendering problem you may still see the same problem even after the import command. In that case don't panic and browse to the root of your installation and refresh the browser.

import is a replace operation, not a merge. Assume that every setting you've ever set in ccHost, including menus, submit forms, virtual roots, etc. will be reset to the values when did the export.

Sharing Configurations Between Machines

Because your different machine is well, different you will need to export and import in a way that accounts for the differences in URLs, local paths, etc.

Export

Browse to media/export

Every browser has some kind of 'Save page' function typically found on the 'File' menu. Use that feature to save the results of the export command to a location on your mirrored setup. For simplicity's sake, let's say the file is called export.txt in the root installation point or your mirror.

Import

These are the steps to a successful configuration import:

  • Make a copy of export.txt and call the copy import.txt.
  • In import.txt search for all occurrences of the root URL in your main setup (e.g. http://example.com/cchost) and replace that with the root URL of your mirrored setup (e.g. http://localhost.)
  • In import.txt search for the location of 'getID3' path (e.g. '/user/bin/getid3') and replace it with your mirrored installation of the getID3 location (e.g. 'c:\utils\web\getid3').
  • There may be other machine paths in import.txt you need to tweak like (e.g. logfiles).
  • On your mirror machine browse to import?i=import.txt. There's nothing that says this operation can't work in reverse, that is: you configure your development machine (mirror) the way you like it, export from there, and import the configuration into your main web server installation.

Automating Import

Here is a PHP script used by ccMixter developers when mirroring their dev machines (this script is provided 'as is' and will break your site if not used properly):

 <?
   /* Replace these define values with ones that
   apply to your situation
   */
   define('EXPORT_FILE', 'd:/cchost/mirror/export.txt');
   define('IMPORT_FILE', 'd:/cchost/mirror/import.txt');
   define('NEW_SERVER', 'http://localhost');
   define('OLD_SERVER', 'http://example.com/cchost');
   define('NEW_GETID3', 'd:/bin/web/getid3');
    
   $text = @file_get_contents(EXPORT_FILE);
   if( empty($text) )
     die("Can't find " . EXPORT_FILE . "\n");
    
   $text = str_replace( OLD_SERVER, NEW_SERVER );
    
   $getid3 = NEW_GETID3;
   $rgs = "#(.*')([^']+getid3)('.*)#";
   $text = preg_replace($rgs, "$1$getid3$3",$text);
    
   /*
   Put the mirror name into the banner
   so we don't get confused about which
   machine we're on!
   */
   $new_server = NEW_SERVER;
   $rgs = "/(.*beta_message['\s]+=> )('[^']*')(.*)/";
   $text = preg_replace($rgs,"$1'ON $new_server'$3", $text);
    
   /*
   Save off a copy of the new config
   This is what we pass to the 'import'
   command.
   */
   $f = fopen( IMPORT_FILE,'w');
   fwrite($f,$text);
   fclose($f);
 ?>


Saving Custom Files

All of the files in your custom file directories should be copied while keeping the exact directory sturcture relative to your root installation.

If you are doing a full backup of your system then save everything under your root installation (might as well). You will probably want to save the content files separately because of their size.

Mirroring Custom Files

If you plan to do extensive development on a site we highly recommend using a version control system like Subversion (SVN). Using something like SVN will automate the syncing of multiple machines.

For a mirror the best thing to do is to install ccHost using the exact same version of the software on the main machine, then copy your files directory to your mirror.