database initialization and backup scripts?

66 views
Skip to first unread message

Rene Veerman

unread,
Jul 22, 2018, 11:48:59 PM7/22/18
to us...@couchdb.apache.org
hi..

i am new to couchdb.

back in SQL land, i'd use to have scripts to both initialize my database,
and scripts to back up and restore my database too.

how would i best implement such scripts in couchdb 2?

Bill Stephenson

unread,
Jul 23, 2018, 12:11:16 AM7/23/18
to us...@couchdb.apache.org
Hi Rene,

The CouchDB docs have info on what you’re looking for:

http://docs.couchdb.org/en/latest/ <http://docs.couchdb.org/en/latest/>

CouchDB has a built-in web based DB manager called Fauxton that makes it easy to create and duplicate databases. Once you’ve installed your CouchDB you can access it at:

https://your.com:6984/_utils/ <https://your.com:6984/_utils/>

You may want to look into PouchDB as well. It’s a Javascript DB that interfaces with CouchDB:

https://pouchdb.com <https://pouchdb.com/>



Bill

Rene Veerman

unread,
Jul 23, 2018, 3:20:02 AM7/23/18
to us...@couchdb.apache.org
hm, and scripts that can be run from the commandline on an ubuntu system?
and preferably able to be run from windows as well?

what would i use for that?..

On Mon, Jul 23, 2018 at 6:11 AM Bill Stephenson <bi...@cherrypc.com.invalid>
wrote:

Hoël Iris

unread,
Jul 23, 2018, 4:05:03 AM7/23/18
to us...@couchdb.apache.org
Hi Rene,

You can try https://github.com/adrienverge/coucharchive

It helps creating archive of a whole couch, not just one db, with CLI.

Johs. E

unread,
Jul 24, 2018, 7:23:59 AM7/24/18
to us...@couchdb.apache.org
Hi Rene,
Some things are so easy in CouchDB that you would not even write a script for it.
Setting up a database can be done by a click in Fauxton (or an alternative GUI to CouchDB https://github.com/ermouth/couch-photon)
Or at command line level use curl (some docs to start with here http://docs.couchdb.org/en/2.1.2/intro/tour.html)

Backup and restore is easy to do by replication, CouchDB’s killer feature #1 http://docs.couchdb.org/en/2.1.2/replication/index.html

J

Rene Veerman

unread,
Aug 2, 2018, 11:54:05 AM8/2/18
to us...@couchdb.apache.org
ok, i've figured out how to keep my old way of initializing and resetting
things in my CMS seductiveapps.com :

i have a PHP script
https://gitlab.com/seductiveapps/seductiveapps/blob/master/seductiveapps/siteData/reInit.php
that via
https://gitlab.com/seductiveapps/seductiveapps/blob/master/boot_stage_001.php
->
https://gitlab.com/seductiveapps/seductiveapps/blob/master/seductiveapps/functions.php
:: couchdb_address() and the credentials (loaded via
https://gitlab.com/seductiveapps/seductiveapps/blob/master/seductiveapps/globals.php
:: global $saCouchDB) in
https://gitlab.com/seductiveapps/seductiveapps/blob/master/config.localhost.couchdb.json
or
https://gitlab.com/seductiveapps/seductiveapps/blob/master/config.seductiveapps.com.couchdb.json
(whichever is the server domain name for the current server),
correctly initializes my couchdb, including the removal of old databases.

using a .php site-wide re-init script allows me to start afresh whenever i
need to, from anywhere,
and i will be able to implement .php site backup and site restore scripts
as well, using probably something like adrienverge's coucharchive, and
listing a backup as a folder path instead of a zip file path to save time
during backup and restore operations.

i have chosen to use php-couchdb (
https://github.com/ibm-watson-data-lab/php-couchdb, which is fairly easy to
install on ubuntu at least, if you follow the instructions) and to augment
and patch it where necessary.
it's undergoing semi-active development, and even more importantly : it's
MIT / Apache licensed, so can be used in commercial / closed-source /
originally-licensed software without violating licensing terms.
php-on-couchdb is GPL3, and that's an infectious license. you have to
publish your own stuff as GPL3 as well if you use any GPL3 software. don't
say i didn't warn you ;)
as far as i know, only MIT / LGPL / Apache licenses are safe for commercial
usage.

together with using git for the source-codes (gitlab.com instead of
github.com because you never know if github's new owner Microsoft will
quietly add licensing terms to github that effectively nullify any license
you put on software that you publish there),
i will have a very robust set of easy scripts to manage my CMS
seductiveapps with, all php, except for one shell script (
https://gitlab.com/seductiveapps/seductiveapps/blob/master/updateLiveServer.sh),
which fetches from gitlab whatever i put on there from my development
machine.

i thank you all for your earlier tips in this thread, but i believe this
solution i'm at now to be the easiest for me to manage.

there's one more thing i'd like to mention : for the javascript side, i use
pouchdb (https://pouchdb.com/guides/setup-pouchdb.html), and there's one
note-worthy thingy i'd like to mention here :
walking through an array of items that might need changing, and how
pouchdb's asynchronous nature can mess up a simple for loop.
the cure for that is at
https://gitlab.com/seductiveapps/seductiveapps/blob/master/seductiveapps/businessLogic/saTree/1.0.0/saTree-1.0.0.source.js
, in the handler for .on('activate_node.jstree', function (e, data)

i mention all of this of course to save other people a significant search
for a realistic couchdb PHP + JS stack.

the only thing i haven't figured out yet is how to set security settings on
the couchdb from PHP. i don't know if i can keep nginx with it's
reverse-proxy features out of the loop, i'd like to of course, until i need
nginx for it's load balancing features.
but i'll dig into that later tonight or tomorrow or sometime in the next
few weeks.

Rene Veerman

unread,
Aug 9, 2018, 1:29:44 PM8/9/18
to us...@couchdb.apache.org
i've chosen to extend php-couchdb to set database permissions from the
siteData/reInit.php script.
the ticket for this is at
https://github.com/ibm-watson-data-lab/php-couchdb/issues/13

it's among my top priorities to get this done, and i think i can have it
completed within 2 weeks.
Reply all
Reply to author
Forward
0 new messages