#!/usr/bin/python2.7 """notes: Dump the database into a tar file. The dump file will be called 'dump_{ISO date}.tar.gz' using today's date. Create the dump file in the directory specified by BACKUP_DIR variable in the settings, otherwise in the current working directory. """ from __future__ import print_function, absolute_import import os import sys import time from notes import settings from notes import utils if __name__ == '__main__': args = utils.get_args('Dump database into tar file.') utils.load_settings(filepath=args.settings, verbose=args.verbose) db = utils.get_db() filepath = "dump_{}.tar.gz".format(time.strftime("%Y-%m-%d")) try: filepath = os.path.join(settings['BACKUP_DIR'], filepath) except KeyError: pass utils.dump(db, filepath, verbose=args.verbose)
#!/usr/bin/python2.7 "notes: Load all CouchDB database design documents." from __future__ import print_function, absolute_import from notes import utils if __name__ == '__main__': args = utils.get_args(description='Reload all CouchDB design documents.') utils.load_settings(filepath=args.settings, verbose=args.verbose) utils.load_designs(utils.get_db(), verbose=args.verbose)
#!/usr/bin/python2.7 """notes: Initialize the database, working directly towards CouchDB. 1) Wipeout the old database. 2) Load the design documents. 3) Load the dump file, if any. """ from __future__ import print_function, absolute_import import sys from notes import utils def init_database(verbose=False, dumpfilepath=None): db = utils.get_db(create=True) utils.wipeout_database(db) if verbose: print('wiped out database', file=sys.stderr) utils.load_designs(db) if verbose: print('loaded designs', file=sys.stderr) if __name__ == '__main__': args = utils.get_args() utils.load_settings(filepath=args.settings, verbose=args.verbose) init_database(verbose=args.verbose)
#!/usr/bin/python2.7 """notes: Undump the database from a tar file. The items from the tar file will be added to the database, ignoring any existing items. """ from __future__ import print_function, absolute_import import os import sys import time from notes import settings from notes import utils if __name__ == '__main__': args = utils.get_args(description='Undump tar file into database.', argdefs=[(['dumpfile'], {'metavar': 'DUMPFILE', 'type': str, 'nargs': 1, 'help': 'dump file'})]) utils.load_settings(filepath=args.settings, verbose=args.verbose) db = utils.get_db() utils.undump(db, args.dumpfile[0], verbose=args.verbose)