MySQL backup mod for sNews
filed under: sNews CMS / Hacks & Mods
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.
16 comments
Add a new comment »Categories
Recent Entries
Recent Comments
- Redbeard (I managed to get Vampire: The Masquerade - Bloodlines ...)
- Tina (Installed this today and working like a charm :) Thanks!)
- Tina (Thanks for this great mod :) Working on my site for quite a ...)
- konga (Hi Matt, if you plan to update it, please have a look into ...)
- David (Yo Matt, I have a problem, when I use this mod. ...)
- Dave (Have a Toshiba NB305. Win7 starter would not do screen ...)
- Daichisan (Howdy Matt, I dont really get it, whats ...)
- Matt (Mine is just customized further, that's all :) It just spits ...)
- Matt (David, Do you own or admin the server? Do you have exec ...)
Popular Entries
- Compact archives for sNews 1.7 (5/5)
- Light-weight related articles mod for sNews 1.7 (4.78/5)
- SEF / SEO search for your sNews website (4.75/5)
- 1024x600 netbook wallpapers of Evangeline Lilly (4.67/5)
- Gravatar mod for sNews 1.7 (4.67/5)
- An improved tag cloud for sNews 1.7 (4.67/5)
- Image / math hybrid captcha version 2, vastly improved (4.64/5)
- Related Articles mod for sNews CMS, public beta release (4.6/5)
- An easy mod to create custom break titles for your sNews articles (4.6/5)


Feb 27th, 2009 at 8:26 pm
Thanks MDJ!
PP
May 1st, 2009 at 7:01 pm
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
Jul 2nd, 2009 at 4:18 am
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?
Jul 2nd, 2009 at 7:10 am
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?
http://snewscms.com/forum/index.php?topic=4598.msg30863
The filename is based on the database name with a date stamp appended.
Aug 22nd, 2009 at 2:44 am
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.
Apr 10th, 2010 at 3:20 am
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.
Apr 10th, 2010 at 8:50 am
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
Apr 10th, 2010 at 2:12 pm
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)
Apr 10th, 2010 at 3:40 pm
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=8547.0
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/11/getting_through.html
Apr 11th, 2010 at 3:27 pm
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
Aug 19th, 2010 at 4:45 pm
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
Aug 20th, 2010 at 8:30 am
Daichisan,
I would guess that you probably have PHP running in safe mode, but it's hard to say without checking server error logs.
Aug 20th, 2010 at 9:22 am
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
Aug 20th, 2010 at 12:17 pm
Yo Matt,
I have safe_mode Off Off
What can be here the reason? Does it work on snews 1.7?
Tnx
Aug 20th, 2010 at 1:10 pm
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.
Aug 20th, 2010 at 1:42 pm
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