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.


Comments
RSS Comments Feed
Poppoll
PP
K4iTO
THX MDJ for it :D
Bocaj1
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?
Matt
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.
slemborg
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.
Jokkman
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.
Matt
Regardless, here is the source file, just save as mod.backup.php.
http://www.mdj.us/media/mod.backup.phps
Jokkman
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)
Matt
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
Jokkman
Daichisan
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
Matt
I would guess that you probably have PHP running in safe mode, but it's hard to say without checking server error logs.
Daichisan
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
David
I have safe_mode Off Off
What can be here the reason? Does it work on snews 1.7?
Tnx
Matt
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.
Daichisan
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
John Flower