Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
18 posts Page 1 of 2
This is a simple utility that provides basic tools for backing up and restoring the database on your Couch site. To install it, download and unzip the attached file. Place the entire "database" folder in your couch folder.

Quick Start
Go to site.com/couch/database/ while logged in as an admin. Push the buttons.

Backup, Download, Restore, Sync
The Database Utility includes simple functions to quickly save, download, or restore a database backup. To sync between a live site and your local copy, simply take a backup from one and restore it to the other.

Manage Backups
A simple file manager allows you to download, rename, or delete your saved backup files.

Automatic Backups
The thing about Database Backups is that you almost never need one, but when you do, you need it really, really bad. For this reason automatic backups are much preferable to manual backups which you're likely to forget or fall behind on. This utility now includes a script for making automatic backups using a cron job. Don't be scared off if the idea of a cron job is unfamiliar to you. It's really pretty easy.

You'll find a tab in your cPanel for setting up Cron Jobs. Start by setting the interval for running the backup script. For relatively simple sites, I save a backup once a week. For a more active site or one with crucial data, you may want to save backups more frequently. However, the file naming convention for cron backups does not support more than one backup per day.

Next enter the command that you want to run. The "Configure a Cron Job" button will help you create the command for calling the backup script.

Host Restrictions
Some hosts won't allow you to call a cron job from your public_html folder. Normally, these hosts require scripts to be in the cgi-bin. In this case, you will need a hard-coded script to run outside of the Couch folder. But never fear. This utility can create the script for you. You can download a custom script and place it in your cgi-bin (or wherever the host requires). You will need to use the correct path/to/the/file when you set up the cron job, but that won't be too hard to figure out.

If you run into complications, don't get frustrated. Automatic database backups are well worth the effort.


Cautions
As with any database operation, be sure you have a good backup before proceeding with the restore operation.

This utility backs up and restores the entire database, not just the Couch tables. If your site has a database to itself, like most sites, then that's a good thing. But if your site shares a database - for example by using prefixes to install multiple Couch instances on the same database - you might have conflicts.

System Paths
The functions used by this utility for backing up and restoring the database are system commands (like you would type into a terminal), not PHP functions. The path to these system commands is different depending on your system and server configuration. This utility does its best to automatically determine the correct path, but if the utility throws errors or creates 0 byte files, you can configure the paths manually in the couch/database/config.php file.

Some hosts may not allow PHP to access the system commands for security purposes. If that's the case, then this utility simply won't work.

https://github.com/fallingsprings/couch ... r/database

Attachments

:mrgreen: Now this is great!

I want to see someone also posts a feedback. It didn't restore on my side.
I don't want to post all the environment vars to pinpoint the issue immediately, so let people also test it first. Just to make sure, the problem is not only on my side (as i don't use wamp).

The tool showed up correctly, then successfully downloaded the backup.
Upon restoration it didn't delete/overwrite previous db.
Restore of backup file with phpmyadmin was successful.
The tool showed up correctly, then successfully downloaded the backup.
Upon restoration it didn't delete/overwrite previous db.
Restore of backup file with phpmyadmin was successful.

Did you backup from your live server (successfully) and then try to restore (unsuccessfully) on the local server? Server configuration can interfere with PHP accessing the mysql commands, and local servers can be quirky.

The utility should throw an error when it can't find the path to the mysql functions. Did you get an error about server configuration, or did it seem to work but just didn't?

The same happened to me in my local MAMP environment while I was developing this tool. A fix is included in the 3 files for correcting the pathname to work in a MAMP environment. If you're using XAMPP or another local server stack, you can find out the right path and include it in these same places. For example:
Code: Select all
/Application/XAMPP/xamppfiles/bin/mysqldump
~and~
/Application/XAMPP/xamppfiles/bin/mysql

Hope that helps. I was kind of nervous about running into this sort of issue, because I'm not really qualified to go very far trying to troubleshoot system and server issues. But I encourage any sort of feedback or suggestions to try to improve and stabilize this utility.
@trendoman, I updated the utility with more rigorous error testing and reporting, as well as a config file for configuring the path to the mysql functions. Maybe it will help with the issue you ran into.
Even better, I hope :) This one sets the mysql base directory automatically.
Auto dir is very nice. Much better )
What I have is 2 things:
1. Unknown error. Cannot restore backup file. Error Code: 7
2. c:\cloud\openserver\modules\database\MySQL-5.5/bin/mysql: unknown variable 'innodb=OFF'

All your restore queries are always like this..
151229 4:35:44 21 Connect dbdemo@localhost on
21 Query SET NAMES utf8
21 Init DB dbdemo
21 Query SET NAMES 'utf8'
21 Query SET COLLATION_CONNECTION=utf8_general_ci
21 Query SET sql_mode = ''
21 Query select k_value from couch_settings where k_key='k_couch_version'
21 Query SELECT * FROM couch_settings WHERE k_key='secret_key'
21 Query SELECT * FROM couch_users WHERE name='admin'
21 Query SHOW VARIABLES LIKE 'basedir'

Backup went successfully.
Download was 0 bytes (latest Chrome). The file in backup dir was okay, around 30kb.
Earlier (previous versions) downloaded without issues.
If you want to see logs of apache and mysql you can use my openserver environment. Perfectly shows logs for debug. Can pm you link with archive.
Hi trendoman :) Thanks for your help troubleshooting this problem. I might be in over my head trying to accommodate different server environments :? But I'm wondering if the direction of the slashes might be causing the problem in your environment?
2. c:\cloud\openserver\modules\database\MySQL-5.5/bin/mysql: unknown variable 'innodb=OFF'

If you change config.php to the following, does it work?
Code: Select all
    $mysql_path = mysql_query( "SHOW VARIABLES LIKE 'basedir'" );
    $mysql_path = mysql_fetch_array($mysql_path);
    $environment = explode('\\', $mysql_path[1]);
    if ( !$environment[1] ){
        define( 'MYSQL_PATH', $mysql_path[1].'/bin/' );
    }else{
        define( 'MYSQL_PATH', $mysql_path[1].'\bin\\' );
    }
Don't worry, I will to test it out fully and try to resolve the issue too. Unfortunately, now there is no time for play, as this can be time consuming. I promise to get back to this as soon as i'm done with a v.imp. project. It will be next week, I suppose. By that time we might also receive more feedback from others. Thank you!
I understand, @trendoman. For now I'll post the latest working-for-me version here, including automatic directory detection with slash orientation.
A new version of this utility is now available from the download at the top of the thread.

I hope it addresses the issues on your system, @trendoman, but it also includes a complete overhaul of the structure and design of the code, security enhancements, and a simple file manager for handling saved backups.
18 posts Page 1 of 2
cron