Back up Cms

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
User avatar
blast2007
Power Poster
Power Poster
Posts: 508
Joined: Wed Aug 01, 2007 5:36 pm

Re: Back up Cms

Post by blast2007 »

essexboyracer wrote: what about encrypting the tar archive? I did a quick search and found this
This could be a good idea.
If you're planning to use Unix/like system you can take a look at this post
With windows client you could use winscp or similar to download backup files.

Regards
blast
essexboyracer
Forum Members
Forum Members
Posts: 85
Joined: Wed Jun 20, 2007 5:40 pm

Re: Back up Cms

Post by essexboyracer »

im just posting this here so i dont forget in the morning

1. Paste the following into a text file and save it as test.php, then upload and run in browser (http://us2.php.net/manual/en/function.shell-exec.php)

$output";
?>

It will test whether we can run linux commands from php. for example the above will output on my 1and1 business hosting account (which doesn't have ssh therefore no sFTP) the list of files in the current (public_html - where test.php resides) directory.

2. If that works, the next step is to look for some package (not sure what it is yet, mcrypt outputs nothing while openssl outputs something, which is a bonus). I found the following at http://kerneltrap.org/node/2737

    ENCRYPTION:

    tar -zcvf - stuff|openssl des3 -salt -k secretpassword | dd of=stuff.des3

    This will create stuff.des3...don't forget the password you put in place of  secretpassword.

    dd if=stuff.des3 |openssl des3 -d -k secretpassword|tar zxf -

    Ok above there is a "-" at the end... this will extract everything.

The above works on my gutsy gibbon setup at home. havent had the time to try yet on 1and1.

Once all the above works, create a script to be run from the cli so it can be cron'd.

Things to do:

Work out what tools are available for encryption on my hosting e.g. 1and1
Work out the command to encrypt  tar archives with the tools available on my hosting package
create the script to do the above
Last edited by essexboyracer on Sat Mar 08, 2008 6:39 am, edited 1 time in total.
essexboyracer
Forum Members
Forum Members
Posts: 85
Joined: Wed Jun 20, 2007 5:40 pm

Re: Back up Cms

Post by essexboyracer »

DO NOT use on production sites.

Save it all into a file whatever.php and upload to web accessible directory to test it. This is as far as I have gotten with this so if anyone else wants to chip in then fine.Eventually the idea is for whatever.php to be run from CRON.

&1 at the end of the following commands will help debugging

mcrypt encryption command to test
Below will tell you if you can use mcrypt in your shell, call it in your browser

&1');
    echo "$output";
?>

on my 1and1 , this is a no! I would have liked mcrypt as you can -z gzip directly from it
if yours is a yes then google mcrypt

openssl encryption command to test
Below will tell you if you can use openssl in your shell, call it in your browser

&1');
    echo "$output";
?>

on my 1and1 , this is a yes!

*/

$today = date('d-m-y');

//
// CHANGE THESE
//

$secret_phrase = 'yourPasswordHere';

// db username
$dbusername = 'username';

// db password
$dbpassword = 'password';

// db hostname (normally required for 1and1, if not then localhost will normally do)
$dbhost = 'localhost';

// Document Root
$document_root = '/path/to/htdocs/';

// Folder/File to archive
$file = 'cmsms';

// Complete path
$compath = $document_root . $file;

//
// DONT CHANGE ANYTHING BELOW
//

// MySQL Backup command - will dump and zip the database
$command = 'mysqldump -u' . $dbusername . ' -p' . $dbpassword . ' --host=' . $dbhost . ' --opt -A > ' . $compath . '/sqlbackup_' . $today . '.sql';

// Get the script to wait 5 seconds
$command .= ' ; sleep 5 ; ';

/*
// unsue of the following - need more testing
// gzip the database - not sure if this works ok, TRY IT!
$command .= 'gzip -f -q ' . $compath . '/sqlbackup_' . $today . '.sql > ' . $document_root . 'db_dump_' . $today . '.sql.gz';
*/
//$command .= ' ; sleep 5 ; ';

// TAR Archive Command to run
$command .= 'tar -cvf ' . $document_root . $today . '.tgz ' . $compath . '';

$command .= ' ; sleep 5 ; ';

// OpenSSL command to run
$command .= 'openssl enc -aes-256-cbc -salt -in ' . $document_root . $today . '.tgz -out ' . $document_root . 'backup' . $today . '.enc -pass pass:' . $secret_phrase . '';

$command .= ' ; sleep 5 ; ';

// Remove the tgz file so we only have the encrypted backup file left
$command .= 'rm -f ' . $document_root . $today . '.tgz';

// remove the sql file
$command .= 'rm -f' . $compath . '/sqlbackup_' . $today . '.sql';

// Run everything
$output = shell_exec($command . ' 2>&1');

// Show any output
echo "$output";
?>
Last edited by essexboyracer on Sun Mar 09, 2008 5:25 pm, edited 1 time in total.
Locked

Return to “The Lounge”