Ejemplo n.º 1
0
    def _create_extras(self, extras, profile, conf):
        os.mkdir(extras.path)
        os.chmod(extras.path, 0700)

        etc = str(extras.etc)
        os.mkdir(etc)
        self._log("  mkdir " + etc)

        self._log("\n// needed to automatically detect and fix file ownership issues\n")

        shutil.copy("/etc/passwd", etc)
        self._log("  cp /etc/passwd " + etc)

        shutil.copy("/etc/group", etc)
        self._log("  cp /etc/group " + etc)

        if not conf.skip_packages or not conf.skip_files:
            self._log("\n" + fmt_title("Comparing current system state to the base state in the backup profile", '-'))

        if not conf.skip_packages and exists(profile.packages):
            self._write_new_packages(extras.newpkgs, profile.packages)

        if not conf.skip_files:
            # support empty profiles
            dirindex = profile.dirindex if exists(profile.dirindex) else "/dev/null"
            dirindex_conf = profile.dirindex_conf if exists(profile.dirindex_conf) else "/dev/null"

            self._write_whatchanged(extras.fsdelta, extras.fsdelta_olist,
                                    dirindex, dirindex_conf,
                                    conf.overrides.fs)

        if not conf.skip_database:

            try:
                if mysql.MysqlService.is_running():
                    self._log("\n" + fmt_title("Serializing MySQL database to " + extras.myfs, '-'))
                    mysql.backup(extras.myfs, extras.etc.mysql,
                                 limits=conf.overrides.mydb, callback=mysql.cb_print()) if self.verbose else None

            except mysql.Error:
                pass

            try:
                if pgsql.PgsqlService.is_running():
                    self._log("\n" + fmt_title("Serializing PgSQL databases to " + extras.pgfs, '-'))
                    pgsql.backup(extras.pgfs, conf.overrides.pgdb, callback=pgsql.cb_print() if self.verbose else None)
            except pgsql.Error:
                pass
Ejemplo n.º 2
0
    def database(self):
        if not exists(self.extras.myfs) and not exists(self.extras.pgfs):
            return

        if self.rollback:
            self.rollback.save_database()

        if exists(self.extras.myfs):

            print "\n" + self._title("Restoring MySQL databases")

            try:
                mysql.restore(self.extras.myfs, self.extras.etc.mysql,
                              limits=self.limits.mydb, callback=mysql.cb_print(), simulate=self.simulate)

            except mysql.Error, e:
                print "SKIPPING MYSQL DATABASE RESTORE: " + str(e)
Ejemplo n.º 3
0
    def database(self):
        if not exists(self.extras.myfs) and not exists(self.extras.pgfs):
            return

        if self.rollback:
            self.rollback.save_database()

        if exists(self.extras.myfs):

            print fmt_title("DATABASE - unserializing MySQL databases from " +
                            self.extras.myfs)

            try:
                mysql.restore(self.extras.myfs,
                              self.extras.etc.mysql,
                              limits=self.limits.mydb,
                              callback=mysql.cb_print(),
                              simulate=self.simulate)

            except mysql.Error, e:
                print "SKIPPING MYSQL DATABASE RESTORE: " + str(e)
Ejemplo n.º 4
0
            usage()

    if not args:
        usage()

    myfs = args[0]
    limits = args[1:]

    if opt_tofile:
        if opt_tofile == '-':
            fh = sys.stdout
        else:
            fh = file(opt_tofile, "w")
    else:
        fh = mysql.mysql(**myconf)

    callback = None
    if opt_verbose:
        print "destination: " + fh.name
        callback = mysql.cb_print()

    if opt_verbose:
        pass

    mysql.fs2mysql(fh, myfs, limits, callback, 
                   opt_skip_extended_insert,
                   opt_add_drop_database)

if __name__ == "__main__":
    main()
Ejemplo n.º 5
0
    def _create_extras(self, extras, profile, conf):
        os.mkdir(extras.path)
        os.chmod(extras.path, 0700)

        etc = str(extras.etc)
        os.mkdir(etc)
        self._log("  mkdir " + etc)

        self._log(
            "\n// needed to automatically detect and fix file ownership issues\n"
        )

        shutil.copy("/etc/passwd", etc)
        self._log("  cp /etc/passwd " + etc)

        shutil.copy("/etc/group", etc)
        self._log("  cp /etc/group " + etc)

        if not conf.skip_packages or not conf.skip_files:
            self._log("\n" + fmt_title(
                "Comparing current system state to the base state in the backup profile",
                '-'))

        if not conf.skip_packages and exists(profile.packages):
            self._write_new_packages(extras.newpkgs, profile.packages)

        if not conf.skip_files:
            # support empty profiles
            dirindex = profile.dirindex if exists(
                profile.dirindex) else "/dev/null"
            dirindex_conf = profile.dirindex_conf if exists(
                profile.dirindex_conf) else "/dev/null"

            self._write_whatchanged(extras.fsdelta, extras.fsdelta_olist,
                                    dirindex, dirindex_conf, conf.overrides.fs)

        if not conf.skip_database:

            try:
                if mysql.MysqlService.is_running():
                    self._log("\n" + fmt_title(
                        "Serializing MySQL database to " + extras.myfs, '-'))
                    mysql.backup(
                        extras.myfs,
                        extras.etc.mysql,
                        limits=conf.overrides.mydb,
                        callback=mysql.cb_print()) if self.verbose else None

            except mysql.Error:
                pass

            try:
                if pgsql.PgsqlService.is_running():
                    self._log("\n" + fmt_title(
                        "Serializing PgSQL databases to " + extras.pgfs, '-'))
                    pgsql.backup(
                        extras.pgfs,
                        conf.overrides.pgdb,
                        callback=pgsql.cb_print() if self.verbose else None)
            except pgsql.Error:
                pass
Ejemplo n.º 6
0
    outdir = args[0]
    limits = args[1:]

    if opt_fromfile and myconf:
        fatal("--fromfile incompatible with mysqldump options")

    if opt_delete and isdir(outdir):
        shutil.rmtree(outdir)

    if not exists(outdir):
        os.mkdir(outdir)

    if opt_fromfile:
        if opt_fromfile == '-':
            mysqldump_fh = sys.stdin
        else:
            mysqldump_fh = file(opt_fromfile)
    else:
        mysqldump_fh = mysql.mysqldump(**myconf)

    callback = None
    if opt_verbose:
        print "source: " + mysqldump_fh.name
        callback = mysql.cb_print()

    mysql.mysql2fs(mysqldump_fh, outdir, limits, callback)


if __name__ == "__main__":
    main()