MySQL backup mod for sNews

MySQL backup mod for sNews

My newest mod is a solution to back-up your sNews MySQL database from directly within your sNews administration interface. Rather than just spit out a backup in raw .sql, this mod allows you to compress the file using gzip, bzip2, or even in a password protected zip file, and will email the file to your site administration email address if you choose. You can also view existing backups within your local backup folder, and delete them if you so choose.

This will not work with PHP in safe mode.

Here's a preview (partially obfuscated 'cause I'm paranoid, lol) of what the interface looks like;

Now download the mod file below;

Extract the zip file, and modify the $backup_path in mod.backup.php file to point to the directory you want to use on your server for your backups. Now upload mod.backup.php to the same folder as your snews.php file.

Now lets BACK-UP your snews.php file and work off of a copy.

1. Find the hard coded link items;

$l['cat_listSEF'] = 'archive,contact,sitemap,login,administration,admin_category,admin_article,article_new,extra_new,page_new,snews_categories,snews_articles,extra_contents,snews_pages,snews_settings,snews_files,logout,groupings,admin_groupings';

now we need to add the "snews_backups" page, as in the highlighted code;

$l['cat_listSEF'] = 'archive,contact,sitemap,login,administration,admin_category,admin_article,article_new,extra_new,page_new,snews_backups,snews_categories,snews_articles,extra_contents,snews_pages,snews_settings,snews_files,logout,groupings,admin_groupings';

2. now in the function center, add the following highlighted code, near the end of the function;

case 'snews_files':
    files(); return; break;
case 'snews_backups':
     backups(); return; break;
case 'process':
     processing(); return; break;

3. now in the function administration, add the following highlighted code;

echo '<p><a href="snews_settings/">'.l('settings').'</a></p>
      <p><a href="snews_files/">'.l('files').'</a></p>
      <p><a href="snews_backups/">'.l('backups').'</a></p>
      </fieldset></div>
      <div class="adminpanel">';

4. now copy this backups() function into your snews.php file, just above the closing php tag;

// BACKUPS
function backups() {
    if (file_exists('mod.backup.php')) {
        include_once('mod.backup.php');
        dobackup();
    } else {
        echo "<h2>Oops!</h2><p>I couldn't find the mod file!</p>";
    }
}

5. now open your language file (EN.php in the lang folder), and add the following code block;

#MySQL Backup mod
$l['backups'] = 'Manage MySQL backups';
$l['snews_backups'] = 'MySQL Backups';
$l['create_backup'] = 'Create a Backup';
$l['comp_options'] = 'Compression options:';
$l['comp_zip'] = 'zip';
$l['comp_bzip2'] = 'bzip2';
$l['comp_gzip'] = 'gzip';
$l['comp_none'] = 'none';
$l['backup_password'] = 'Add a password to the zip file';
$l['backup_password2'] = 'Please verify the password';
$l['password_mismatch'] = 'Passwords don\'t match!';
$l['view_backups'] = 'Your local backups in ';
$l['email_backup'] = 'Email a copy of this backup to ';
$l['backup'] = 'Create Backup';
$l['backup_success'] = ' success!';
$l['comp_attempt'] = 'Attempting to compress database file with';
$l['comp_failure'] = ' compression failed!';
$l['email_attempt'] = 'Attempting to email backup file to ';
$l['email_failure'] = ' failed to email file';
$l['email_subject'] = 'Your backup file from ';
$l['operation_time'] = 'operation completed in ';
$l['no_backups'] = 'No backups exist yet';

6. now open your stylesheet and add the following code;

.highlight {background:#ffff88}

7. That's all, now upload your modified language file, stylesheet, and then your snews.php file. Now access the admin section of your sNews installation and you should have the option to manage your mysql database backups. I recommend using the zip option with a strong (non-dictionary) password if you're going to email yourself the files, just in case someone intercepts the file.

Tags

 

You might like

Comments


Thanks MDJ!
PP


I think that this is the best solution what should go to sNews as normal function from version 1.71 and so on...

THX MDJ for it :D


Hi, nice modul.
I'm running PHP with safe mode on, so I'm not allowed to make a new file on the server. Therefor I can't save a backup on my server. What can I do to solved this. Whats the name of the file that this modul creates?


Hi Bocaj1, you're the second person this week to note that can't use this because they run PHP in safe mode. Bummer

There is another mod that doesn't use exec calls, it's not as robust as mine, and it was written for sNews 1.6, perhaps it can be used?
<a href="http://snewscms.com/forum/index.php?topic=4598.msg30863">http://snewscms.com/forum/index.php?topic=4598.msg30863</a>


The filename is based on the database name with a date stamp appended.


Hi.

I justed tested this, and couldn't get it to work, but then, I tried something, the following line:

$backup_path = '/home/username/backups/';

with my added username, did not work
but then I tried the following line:

$backup_path = 'backups/';

which worked flawlessly, so thanks alot for this nifty mod.


Hi

tryed to get this mod to work but it seams that the download zip file misses: mod.backup.php ??
just an execute file in the zipp.


That's odd, maybe the zip got corrupted when you downloaded it because I just redownloaded it and it's there.

Regardless, here is the source file, just save as mod.backup.php.

http://www.mdj.us/media/mod.backup.phps


Tks, going to try it out.
My goal was to have this function in next sNewsTE release... right now we are bugg testing it and it seams to be really fine. I have separate admin panel and switch function, whan you are logedin as admin you can switch between visitor view and admin view (like Wordpress has)


Cool man, however I probably wouldn't roll this into a production system for general release, as it uses exec calls, so people using PHP in safe mode won't be able to use it, and I have no idea how it would perform on a Windows server.

You should have a look at this version, fewer options, but should work on all platforms.

http://snewscms.com/forum/index.php?topic=...

Oh yeah, and if you use MS for email services, you won't get any of the comment notifications, they send them into a black hole.

http://www.webforefront.com/archives/2007/...


Tks MDJ for the fast answer, My thinking was to use some if the code and rewrite the dump function to annother one... but but I integrated this one: http://www.mysqldumper.net/ and it seams to work just fine! (and I have PHP in safe mode on the server)tks again for all the great sNews mods you have done /Jokkman


Attempting to dump database: xxxxxx... dump failed!
Attempting to compress database file with zip...
adding password... compression failed!
sh: zip: command not found

Attempting to email backup file to xxx@xxx.net... success!
operation completed in 0.11 seconds

Why Im getting this errors?!
Help me MDJ, please!

Tnx


Daichisan,

I would guess that you probably have PHP running in safe mode, but it's hard to say without checking server error logs.


Matt!

You are the best! Damnit, give me your brains =) hah jok3, I will take a look and post the result here.

Thanks once again for you help!

David


Yo Matt,

I have safe_mode Off Off
What can be here the reason? Does it work on snews 1.7?

Tnx


David,

Do you own or admin the server? Do you have exec privileges? Maybe a package is missing?

It does work with 1.7 generally.

If you check out the snewscms forum, there is another version that doesn't use exec calls, that will probably work for you. I would recommend trying that if this doesn't work for you.


Howdy Matt,

I dont really get it, whats "exec" and how to turn them on! I have admin privileges.

And where in the snewscms forum is that version, I have only found for 1.6 snews.

Thanks!
David


Flipping sweet. Struggled to get the folder in the right place, and the path correct, but your error message sorted that quick. thanks!

Comments are closed. No new comments allowed.

Copyleft 2002 - 2017 Matt Jones
Hand crafted with HTML5 & CSS3
↑ Back to top