コード例 #1
0
def restore(settings, opt, restoredir, djangoadmin):
    print
    q = textwrap.fill("We are about to to a restore of a backup. " \
            "This action will destroy all data in the database " \
            "and clear all delivered files! Are you sure you want to " \
            "continue? [yes/no]")
    inp = raw_input(q + " ")
    if inp != 'yes':
        raise SystemExit("Restore aborted")

    dbdumpfile = os.path.join(restoredir, "db.json")
    fsdeliverystore_tarfile = os.path.join(restoredir, 'fsdeliverystore.tar.bz2')

    # Clear db
    logging.info("Clearing the database")
    #if settings.DATABASE_ENGINE.startswith('postgresql'):
        #os.system("%(sql sqlreset myapp | sed 's/DROP TABLE
                #\(.*\);/DROP TABLE \1 CASCADE;/g' | psql --username
                #myusername mydbname
    for app in settings.INSTALLED_APPS:
        appname = app.split('.')[-1]
        settingsmod = opt.settings
        cmd = "%(djangoadmin)s reset --settings %(settingsmod)s --noinput %(appname)s" % vars()
        systemcall(cmd)

    # DB restore
    logging.info("Restoring the database from %(dbdumpfile)s..." % vars())
    settingsmod = opt.settings
    systemcall("%(djangoadmin)s loaddata --settings %(settingsmod)s " \
            "%(dbdumpfile)s" % vars())
    logging.info("... database restore complete")

    # Remove existing files
    logging.info("Removing old the delivery-files ...")

    # File restore
    logging.info("Restoring the files ...")
    if settings.DEVILRY_DELIVERY_STORE_BACKEND == 'devilry.core.deliverystore.FsDeliveryStore':
        logging.info("Restoring delivery-files from %(fsdeliverystore_tarfile)s." %
                vars())
        try:
            fsdeliverystore_clear(settings.DELIVERY_STORE_ROOT)
            fsdeliverystore_restore(fsdeliverystore_tarfile,
                    settings.DELIVERY_STORE_ROOT)
        except SystemCallError, e:
            logging.error(str(e))
        logging.info("... delivery-files restore complete")
コード例 #2
0
def fsdeliverystore_restore(tarfile, filesroot):
    cmd = "tar -xvjf %(tarfile)s -C %(filesroot)s" % vars()
    systemcall(cmd)
コード例 #3
0
def fsdeliverystore_backup(tarfile, filesroot):
    cmd = "tar -cvjf %(tarfile)s -C %(filesroot)s ./" % vars()
    systemcall(cmd)