def main(argv: t.List[str] = sys.argv): """Wrapper for pgsql-dump.bash script. :param argv: Command line arguments, second one needs to be the uri to a configuration file. :raises sys.SystemExit: """ if len(argv) < 2: usage_message( argv, additional_params='[ARG1, ARG2]', additional_line='All arguments are passed to pg_dump command') config_uri = get_config_uri(argv) request = init_websauna(config_uri) # Export all secrets and settings bash_env = create_settings_env(request.registry) # subprocess.check_output([DUMP_SCRIPT] + args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env) args = argv[2:] cmd = [DUMP_SCRIPT] + args logger.info("Running %s", " ".join(cmd)) with subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1, env=bash_env, universal_newlines=True) as p: for line in p.stdout: print(line, end='')
def backup_site(): """Run the site backup script. Runs the configured backup script ``websauna.backup_script``. The backup script can be any UNIX executable. The script gets the environment variables from *websauna* configuration, as exposed by :py:func:`websauna.utils.exportenv.create_settings_env`. In the case the backup script fails, an exception is raised and logged through normal application logging means. Run backup from the command line:: echo "from websauna.system.devop import backup ; backup.backup_site()" | pyramid-web20-shell development.ini Note that the output is buffered, so there might not be instant feedback. """ registry = get_current_registry() backup_script_spec = registry.settings.get("websauna.backup_script", "").strip() if not backup_script_spec: # Currently we do not have backup script defined, do not run return resolver = AssetResolver(None) backup_script = resolver.resolve(backup_script_spec).abspath() assert os.path.exists( backup_script), "Backup script does not exist: {}, spec {}".format( backup_script, backup_script_spec) assert stat.S_IXUSR & os.stat(backup_script)[ stat.ST_MODE], "Backup script is not executable: {}".format( backup_script) backup_timeout = int(registry.settings.get("websauna.backup_timeout")) # Export all secrets and settings env = create_settings_env(registry) try: subprocess.check_output([ backup_script, ], timeout=backup_timeout, stderr=subprocess.STDOUT, env=env) except subprocess.CalledProcessError as e: # Capture error to Sentry logger.error(e.output) raise
def main(argv=sys.argv): if len(argv) < 2: usage(argv) config_uri = argv[1] request = init_websauna(config_uri) # Export all secrets and settings bash_env = create_settings_env(request.registry) # subprocess.check_output([DUMP_SCRIPT] + args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env) args = argv[2:] cmd = [DUMP_SCRIPT] + args with subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1, env=bash_env, universal_newlines=True) as p: for line in p.stdout: print(line, end='')
def backup_site(): """Run the site backup script. Runs the configured backup script ``websauna.backup_script``. The backup script can be any UNIX executable. The script gets the environment variables from *websauna* configuration, as exposed by :py:func:`websauna.utils.exportenv.create_settings_env`. In the case the backup script fails, an exception is raised and logged through normal application logging means. Run backup from the command line:: echo "from websauna.system.devop import backup ; backup.backup_site()" | pyramid-web20-shell development.ini Note that the output is buffered, so there might not be instant feedback. """ registry = get_current_registry() backup_script_spec = registry.settings.get("websauna.backup_script", "").strip() if not backup_script_spec: # Currently we do not have backup script defined, do not run return resolver = AssetResolver(None) backup_script = resolver.resolve(backup_script_spec).abspath() assert os.path.exists(backup_script), "Backup script does not exist: {}, spec {}".format(backup_script, backup_script_spec) assert stat.S_IXUSR & os.stat(backup_script)[stat.ST_MODE], "Backup script is not executable: {}".format(backup_script) backup_timeout = int(registry.settings.get("websauna.backup_timeout")) # Export all secrets and settings env = create_settings_env(registry) try: subprocess.check_output([backup_script,], timeout=backup_timeout, stderr=subprocess.STDOUT, env=env) except subprocess.CalledProcessError as e: # Capture error to Sentry logger.error(e.output) raise