def backup(wp_env, wp_url, full=False, **kwargs): wp_backup = WPBackup(wp_env, wp_url, full) if not wp_backup.backup(): raise SystemExit("Backup failed. More info above") print("Successful {} backup for {}".format(wp_backup.backup_pattern, wp_backup.wp_site.url))
def backup(wp_env, wp_url, backup_type=None, **kwargs): wp_backup = WPBackup(wp_env, wp_url, backup_type=backup_type) if not wp_backup.backup(): raise SystemExit("Backup failed. More info above") print("Successfully backed-up WordPress site for {}".format( wp_backup.wp_site.url))
def rotate_backup_inventory(path, dry_run=False, **kwargs): if dry_run: logging.info("! DRY RUN !") for site_details in WPConfig.inventory(path): if site_details.valid == settings.WP_SITE_INSTALL_OK: try: path = WPBackup( WPSite.openshift_env_from_path(site_details.path), site_details.url).path # rotate full backups first for pattern in [["*full.sql"], ["*full.tar", "*full.tar.gz"]]: RotateBackups(FULL_BACKUP_RETENTION_THEME, dry_run=dry_run, include_list=pattern).rotate_backups(path) # rotate incremental backups for pattern in [["*.list"], ["*inc.sql"], ["*inc.tar", "*inc.tar.gz"]]: RotateBackups(INCREMENTAL_BACKUP_RETENTION_THEME, dry_run=dry_run, include_list=pattern).rotate_backups(path) except: logging.error("Site %s - Error %s", site_details.url, sys.exc_info())
def backup_inventory(path, dry_run=False, **kwargs): """ Backup all WordPress instances found in a given path :param path: :param dry_run: :param kwargs: :return: """ if dry_run: logging.info("! DRY RUN !") logging.info("Backup from inventory...") for site_details in WPConfig.inventory(path): if site_details.valid == settings.WP_SITE_INSTALL_OK: logging.info("Running backup for %s", site_details.url) try: WPBackup(WPSite.openshift_env_from_path(site_details.path), site_details.url, dry_run=dry_run).backup() except: logging.error("Site %s - Error %s", site_details.url, sys.exc_info()) logging.info("All backups done for path: %s", path)
def rotate_backup(csv_file, dry_run=False, **kwargs): if dry_run: logging.info("! DRY RUN !") # CSV file validation validator = _check_csv(csv_file) for index, row in enumerate(validator.rows): try: path = WPBackup(row["openshift_env"], row["wp_site_url"]).path # rotate full backups first for pattern in [["*full.sql"], ["*full.tar", "*.full.tar.gz"]]: RotateBackups(FULL_BACKUP_RETENTION_THEME, dry_run=dry_run, include_list=pattern).rotate_backups(path) # rotate incremental backups for pattern in [["*.list"], ["*inc.sql"], ["*inc.tar", "*inc.tar.gz"]]: RotateBackups(INCREMENTAL_BACKUP_RETENTION_THEME, dry_run=dry_run, include_list=pattern).rotate_backups(path) except: logging.error("Site %s - Error %s", row["wp_site_url"], sys.exc_info())
def setup(): # clean WP site wp_generator = MockedWPGenerator({'openshift_env': OPENSHIFT_ENV, 'wp_site_url': SITE_URL_SPECIFIC}) wp_generator.clean() # clean backups backup_path = WPBackup(OPENSHIFT_ENV, SITE_URL_SPECIFIC).path shutil.rmtree(backup_path, ignore_errors=True)
def backup_many(csv_file, **kwargs): # CSV file validation validator = _check_csv(csv_file) # create a new WP site backup for each row print("\n{} websites will now be backuped...".format(len(validator.rows))) for index, row in enumerate(validator.rows): logging.debug("%s - row %s: %s", row["wp_site_url"], index, row) WPBackup(row["openshift_env"], row["wp_site_url"]).backup()
def backup_many(csv_file, backup_type=None, **kwargs): # use Veritas to get valid rows rows = VeritasValidor.filter_valid_rows(csv_file) # create a new WP site backup for each row print("\n{} websites will now be backuped...".format(len(rows))) for index, row in rows: logging.debug("%s - row %s: %s", row["wp_site_url"], index, row) WPBackup(openshift_env=row["openshift_env"], wp_site_url=row["wp_site_url"], wp_default_site_title=row["wp_default_site_title"], backup_type=backup_type).backup()
def rotate_backup(csv_file, dry_run=False, **kwargs): # CSV file validation validator = _check_csv(csv_file) for index, row in enumerate(validator.rows): path = WPBackup(row["openshift_env"], row["wp_site_url"]).path # rotate full backups first for pattern in ["*full.sql", "*full.tar"]: RotateBackups(FULL_BACKUP_RETENTION_THEME, dry_run=dry_run, include_list=[pattern]).rotate_backups(path) # rotate incremental backups for pattern in ["*.list", "*inc.sql", "*inc.tar"]: RotateBackups(INCREMENTAL_BACKUP_RETENTION_THEME, dry_run=dry_run, include_list=[pattern]).rotate_backups(path)
def backup_inventory(path, **kwargs): logging.info("Backup from inventory...") for site_details in WPConfig.inventory(path): if site_details.valid == settings.WP_SITE_INSTALL_OK: logging.info("Running backup for %s", site_details.url) try: WPBackup(WPSite.openshift_env_from_path(site_details.path), site_details.url).backup() except: logging.error("Site %s - Error %s", site_details.url, sys.exc_info()) logging.info("All backups done for path: %s", path)