changed so sync now goes TO the destination branch, also changed variable name fro clarity

modified:   modules/database.py
This commit is contained in:
Ronny Abraham 2016-11-08 19:33:49 +02:00
parent 441f8b4be6
commit 7d6c179f6a

View file

@ -2,7 +2,7 @@ from fabric.api import env, task
# # from jinja2 import Environment # # from jinja2 import Environment
import os import os
from utils import upload_template as utils_upload_template from utils import upload_template as utils_upload_template
from utils import loggify, print_console from utils import loggify, print_console, booleanize
# from utils import prompt_continue # from utils import prompt_continue
from getpass import getpass from getpass import getpass
import fabric.operations as fabric_ops import fabric.operations as fabric_ops
@ -229,14 +229,14 @@ def commandline(dbuser='default'):
@task @task
def backup(dbuser='default', backup_file=None, branch=None, def backup(dbuser='default', backup_file=None, branch=None,
filedump_only=False): datadump_only=False):
""" """
creates a dump of the database for backup and storage creates a dump of the database for backup and storage
dbuser - set to "default" but can also be set to "admin" dbuser - set to "default" but can also be set to "admin"
backup_file - specify name of the backup_file otherwise use default value backup_file - specify name of the backup_file otherwise use default value
branch - what branch to apply this function to (default env.current) branch - what branch to apply this function to (default env.current)
filedump_only - only output the results of pg_dump datadump_only - only output the results of pg_dump
the admin user is what it says, I have both of these in case I need to the admin user is what it says, I have both of these in case I need to
switch between the master user for the entire postgres install or the owner switch between the master user for the entire postgres install or the owner
@ -276,7 +276,11 @@ def backup(dbuser='default', backup_file=None, branch=None,
configuration.paths.server.backups.database, configuration.paths.server.backups.database,
backup_file) backup_file)
if not filedump_only: datadump_only = booleanize(datadump_only)
print "dumpfilename: %s" % dumpfilename
if not datadump_only:
# NOTE # NOTE
# the "tee" command takes input and pipes it to a file and to standard # the "tee" command takes input and pipes it to a file and to standard
@ -289,6 +293,7 @@ def backup(dbuser='default', backup_file=None, branch=None,
user=user, user=user,
dumpfilename=dumpfilename dumpfilename=dumpfilename
) )
else: else:
# this only spits output, it does not save a file # this only spits output, it does not save a file
@ -300,7 +305,9 @@ def backup(dbuser='default', backup_file=None, branch=None,
user=user, user=user,
) )
output = run_database_command(cmd_pg_dump, user, True) print "cmd_pg_dump: %s" % cmd_pg_dump
output = run_database_command(cmd_pg_dump, user)
return output return output
@ -369,18 +376,17 @@ def restore(dbuser='default', backup_file=None, reinitialize=True):
@task @task
def sync(src): def sync(dst):
""" """
sync from source databases to calling branch sync from current branch database to destination branch
src - the source database dst - the destination database
""" """
configuration = env.config configuration = env.config
branch_src = src
import initialize import initialize
configuration_src = initialize.environment(branch_src) branch_dst = dst
configuration_dst = configuration configuration_src = configuration
configuration_dst = initialize.environment(branch_dst)
print "branch_src: %s" % configuration_src.project.branch print "branch_src: %s" % configuration_src.project.branch
print "branch_dst: %s" % configuration_dst.project.branch print "branch_dst: %s" % configuration_dst.project.branch
@ -390,8 +396,13 @@ def sync(src):
backup_name_dst = "backup_sync_dst.sql" backup_name_dst = "backup_sync_dst.sql"
backup_name_src = "backup_sync_src.sql" backup_name_src = "backup_sync_src.sql"
print "output_src = backup("
print "\tbackup_file=%s," % backup_name_src
print "\tbranch=%s)" % configuration_src.project.branch
# dump the source database to our {destination}/backups/database # dump the source database to our {destination}/backups/database
print "backup up src: %s" % configuration_src.project.branch print "backup up src: %s" % configuration_src.project.branch
output_src = backup( output_src = backup(
backup_file=backup_name_src, backup_file=backup_name_src,
branch=configuration_src.project.branch) branch=configuration_src.project.branch)