def _do_file_backup(): """ Generate a backup of files specified on hosts.yml """ if 'file_backups' in server and server['file_backups']['enabled']: _print_output('Generating file backup') # Backup directory name for this backup backup_dir = int(time.time()) # Create backup directory for this backup _check_run_result(run("mkdir %s/%s" % (server['file_backups']['destination_path'], backup_dir))) # Copy files to backup folder with parent structure for file in server['file_backups']['files']: _check_run_result(run("cp -Ra --parents %s %s/%s" % (file, server['file_backups']['destination_path'], backup_dir))) # Delete old backups if server['file_backups']['number_of_backups'] > 0: output = run("ls -t %s | awk '{if(NR>%s)print}'" % (server['file_backups']['destination_path'], server['file_backups']['number_of_backups'])) for file in output.split(): _check_run_result(run("rm -R %s/%s" % (server['file_backups']['destination_path'], file))) _print_ok()
def _do_file_backup(): """ Generate a backup of files specified on hosts.yml """ if 'file_backups' in server and server['file_backups']['enabled']: _print_output('Generating file backup') # Backup directory name for this backup backup_dir = int(time.time()) # Create backup directory for this backup _check_run_result( run("mkdir %s/%s" % (server['file_backups']['destination_path'], backup_dir))) # Copy files to backup folder with parent structure for file in server['file_backups']['files']: _check_run_result( run("cp -Ra --parents %s %s/%s" % (file, server['file_backups']['destination_path'], backup_dir))) # Delete old backups if server['file_backups']['number_of_backups'] > 0: output = run("ls -t %s | awk '{if(NR>%s)print}'" % (server['file_backups']['destination_path'], server['file_backups']['number_of_backups'])) for file in output.split(): _check_run_result( run("rm -R %s/%s" % (server['file_backups']['destination_path'], file))) _print_ok()
def create_database_user(db_user, db_pass): output = sudo('psql -c "select usename from pg_catalog.pg_user"', user = '******') split_output = [x.strip() for x in output.split('\n')] for out in split_output: if out == db_user: print "User already exists, continuing" return sudo('psql -c "CREATE USER %s WITH NOCREATEDB NOCREATEUSER ENCRYPTED PASSWORD E\'%s\'"' % (db_user, db_pass), user='******')
def create_database(db_name, owner_name): output = sudo('psql -c "select datname from pg_database"', user = '******') split_output = [x.strip() for x in output.split('\n')] for out in split_output: if out == db_name: print "Database already exists, continuing" return sudo('psql -c "CREATE DATABASE %s WITH OWNER %s"' % ( db_name, owner_name), user='******')
def create_database(db_name, owner_name): output = sudo('psql -c "select datname from pg_database"', user='******') split_output = [x.strip() for x in output.split('\n')] for out in split_output: if out == db_name: print("Database already exists, continuing") return sudo('psql -c "CREATE DATABASE %s WITH OWNER %s"' % (db_name, owner_name), user='******')
def create_database_user(db_user, db_pass): output = sudo('psql -c "select usename from pg_catalog.pg_user"', user='******') split_output = [x.strip() for x in output.split('\n')] for out in split_output: if out == db_user: print("User already exists, continuing") return sudo( 'psql -c "CREATE USER %s WITH NOCREATEDB NOCREATEUSER ENCRYPTED PASSWORD E\'%s\'"' % (db_user, db_pass), user='******')
def symlink(): """ Creates a symlink to the latest release found using 'ls -xr' """ _init() release_path = _get_attr('releases_path') with cd(release_path): output = run("ls -xr") releases = output.split() releases.reverse() release = releases.pop() release = os.path.join(release_path, release) _status("Symlinking to latest release: %s" % release) with cd(_get_attr('site_root')): current = _get_attr('current_path') run("rm -f %s" % current) run("ln -sf %s %s" % (release, current))
def symlink(): """ Creates a symlink to the latest release found using 'ls -xr' """ _init() release_path = _get_attr("releases_path") with cd(release_path): output = run("ls -xr") releases = output.split() releases.reverse() release = releases.pop() release = os.path.join(release_path, release) _status("Symlinking to latest release: %s" % release) with cd(_get_attr("site_root")): current = _get_attr("current_path") run("rm -f %s" % current) run("ln -sf %s %s" % (release, current))