Пример #1
0
    def backup(self, basedir):
        dispatcher = Dispatcher.os_dispatcher()
        null = open(OSUtils.null_file(), 'w')

        if OS.is_linux():
            Mysql.set_root_pass()

        mysql_password = snap.config.options.service_options['mysql_password']

        # check to see if service is running
        already_running = dispatcher.service_running(Mysql.DAEMON)

        # start the mysql server
        dispatcher.start_service(Mysql.DAEMON)

        # use a pipe to invoke mysqldump and capture output
        outfile = file(basedir + "/dump.mysql", "w")
        popen = subprocess.Popen([
            Mysql.MYSQLDUMP_CMD, "-u", "root", "-p" + mysql_password,
            "--all-databases"
        ],
                                 stdout=outfile,
                                 stderr=null)
        popen.wait()

        # if mysql was stopped b4hand, start up again
        if not already_running:
            dispatcher.stop_service(Mysql.DAEMON)
Пример #2
0
    def restore(self, basedir):
        dispatcher = Dispatcher.os_dispatcher()
        
        record_file = os.path.join(basedir, "service-http.xml")
        
        # if files record file isn't found, simply return
        if not os.path.isfile(record_file):
            return

        # stop the httpd service if already running
        if dispatcher.service_running(Httpd.DAEMON):
            dispatcher.stop_service(Httpd.DAEMON)
            
        # read files from the record file
        record = FilesRecordFile(record_file)
        sfiles = record.read()

        # restore those to their original locations
        for sfile in sfiles:
            sfile.copy_to(path_prefix=basedir)

        # ensure the various subdirs exists even if empty
        if OS.is_linux() and not os.path.isdir(os.path.join(Httpd.DOCUMENT_ROOT, "html")):
            os.mkdir(os.path.join(Httpd.DOCUMENT_ROOT, "html"))
        if OS.is_linux() and not os.path.isdir(os.path.join(Httpd.CONF_D, "logs")):
            os.mkdir(os.path.join(Httpd.CONF_D, "logs"))
        if OS.is_linux() and not os.path.isdir(os.path.join(Httpd.CONF_D, "run")):
            os.mkdir(os.path.join(Httpd.CONF_D, "run"))


        # start the httpd service
        dispatcher.start_service(Httpd.DAEMON)
Пример #3
0
    def set_root_pass():
        '''helper to set the mysql root password'''
        null = open(OSUtils.null_file(), 'w')
        dispatcher = Dispatcher.os_dispatcher()

        mysql_password = snap.config.options.service_options['mysql_password']

        already_running = dispatcher.service_running(Mysql.DAEMON)
        if already_running:
            dispatcher.stop_service(Mysql.DAEMON)

        server = subprocess.Popen(
            [Mysql.MYSQLDSAFE_CMD, '--skip-grant-tables'],
            stdout=null,
            stderr=null)
        client = subprocess.Popen([
            Mysql.MYSQL_CMD, 'mysql', '-u', 'root', '-e',
            "update user set password=PASSWORD('" + mysql_password +
            "') where user='******'; flush privileges;"
        ],
                                  stdout=null,
                                  stderr=null)
        client.wait()
        client = subprocess.Popen([Mysql.MYSQLADMIN_CMD, 'shutdown'],
                                  stdout=null,
                                  stderr=null)
        client.wait()
        if server.poll() == None:  # race condition?
            server.kill()

        if already_running:
            dispatcher.start_service(Mysql.DAEMON)
Пример #4
0
    def restore(self, basedir):
        dispatcher = Dispatcher.os_dispatcher()
        null = open(OSUtils.null_file(), 'w')

        if OS.is_linux():
            Postgresql.set_root_pass()

        # init the postgresql db
        Postgresql.init_db()

        # start the postgresql service
        dispatcher.start_service(Postgresql.DAEMON)

        # get env containing the postgresql password
        penv = Postgresql.set_pgpassword_env()

        # use pipe to invoke postgres, restoring database
        infile = file(basedir + "/dump.psql", "r")
        popen = subprocess.Popen(
            [Postgresql.PSQL_CMD, "--username", "postgres"],
            env=penv,
            stdin=infile,
            stdout=null,
            stderr=null)
        popen.wait()
Пример #5
0
    def backup(self, basedir):
        dispatcher = Dispatcher.os_dispatcher()
        null = open(OSUtils.null_file(), 'w')

        if OS.is_linux():
            Postgresql.set_root_pass()

        # check to see if service is running
        already_running = dispatcher.service_running(Postgresql.DAEMON)

        # start the postgresql server
        dispatcher.start_service(Postgresql.DAEMON)

        # get env containing postgres password
        penv = Postgresql.set_pgpassword_env()

        outfile = file(basedir + "/dump.psql", "w")
        pipe = subprocess.Popen(
            [Postgresql.PGDUMPALL_CMD, "--username", "postgres"],
            env=penv,
            stdout=outfile,
            stderr=null)
        pipe.wait()

        # if postgresql was running b4hand, start up again
        if not already_running:
            dispatcher.stop_service(Postgresql.DAEMON)
Пример #6
0
    def restore(self, basedir):
        dispatcher = Dispatcher.os_dispatcher()

        record_file = os.path.join(basedir, "service-http.xml")

        # if files record file isn't found, simply return
        if not os.path.isfile(record_file):
            return

        # stop the httpd service if already running
        if dispatcher.service_running(Httpd.DAEMON):
            dispatcher.stop_service(Httpd.DAEMON)

        # read files from the record file
        record = FilesRecordFile(record_file)
        sfiles = record.read()

        # restore those to their original locations
        for sfile in sfiles:
            sfile.copy_to(path_prefix=basedir)

        # ensure the various subdirs exists even if empty
        if OS.is_linux() and not os.path.isdir(
                os.path.join(Httpd.DOCUMENT_ROOT, "html")):
            os.mkdir(os.path.join(Httpd.DOCUMENT_ROOT, "html"))
        if OS.is_linux() and not os.path.isdir(
                os.path.join(Httpd.CONF_D, "logs")):
            os.mkdir(os.path.join(Httpd.CONF_D, "logs"))
        if OS.is_linux() and not os.path.isdir(
                os.path.join(Httpd.CONF_D, "run")):
            os.mkdir(os.path.join(Httpd.CONF_D, "run"))

        # start the httpd service
        dispatcher.start_service(Httpd.DAEMON)
Пример #7
0
    def restore(self, basedir):
        dispatcher = Dispatcher.os_dispatcher()
        null = open(OSUtils.null_file(), 'w')

        if OS.is_linux():
            Mysql.set_root_pass()

        mysql_password = snap.config.options.service_options['mysql_password']
        
        # start the mysql server
        dispatcher.start_service(Mysql.DAEMON)

        # use pipe to invoke mysql, restoring database
        infile = file(basedir + "/dump.mysql", "r")
        popen = subprocess.Popen([Mysql.MYSQL_CMD, "-u", "root", "-p" + mysql_password],
                                 stdin=infile, stdout=null, stderr=null)
        popen.wait()

        # flush privileges incase any roles were restored and whatnot
        Mysql.flush_privileges()
Пример #8
0
    def restore(self, basedir):
        dispatcher = Dispatcher.os_dispatcher()
        null = open(OSUtils.null_file(), 'w')
        
        if OS.is_linux():
            Postgresql.set_root_pass()

        # init the postgresql db
        Postgresql.init_db()

        # start the postgresql service
        dispatcher.start_service(Postgresql.DAEMON)

        # get env containing the postgresql password
        penv = Postgresql.set_pgpassword_env()

        # use pipe to invoke postgres, restoring database
        infile = file(basedir + "/dump.psql", "r")
        popen = subprocess.Popen([Postgresql.PSQL_CMD, "--username", "postgres"],
                                 env=penv, stdin=infile, stdout=null, stderr=null)
        popen.wait()
Пример #9
0
    def set_root_pass():
        '''helper to set the mysql root password'''
        null = open(OSUtils.null_file(), 'w')
        dispatcher = Dispatcher.os_dispatcher()
        
        mysql_password = snap.config.options.service_options['mysql_password']
        
        already_running = dispatcher.service_running(Mysql.DAEMON)
        if already_running:
            dispatcher.stop_service(Mysql.DAEMON)

        server = subprocess.Popen([Mysql.MYSQLDSAFE_CMD, '--skip-grant-tables'], stdout=null, stderr=null)
        client = subprocess.Popen([Mysql.MYSQL_CMD, 'mysql', '-u', 'root', '-e', "update user set password=PASSWORD('" + mysql_password + "') where user='******'; flush privileges;"],
                                  stdout=null, stderr=null)
        client.wait()
        client = subprocess.Popen([Mysql.MYSQLADMIN_CMD, 'shutdown'], stdout=null, stderr=null)
        client.wait()
        if server.poll() == None: # race condition?
            server.kill()

        if already_running:
            dispatcher.start_service(Mysql.DAEMON)
Пример #10
0
    def restore(self, basedir):
        dispatcher = Dispatcher.os_dispatcher()
        null = open(OSUtils.null_file(), 'w')

        if OS.is_linux():
            Mysql.set_root_pass()

        mysql_password = snap.config.options.service_options['mysql_password']

        # start the mysql server
        dispatcher.start_service(Mysql.DAEMON)

        # use pipe to invoke mysql, restoring database
        infile = file(basedir + "/dump.mysql", "r")
        popen = subprocess.Popen(
            [Mysql.MYSQL_CMD, "-u", "root", "-p" + mysql_password],
            stdin=infile,
            stdout=null,
            stderr=null)
        popen.wait()

        # flush privileges incase any roles were restored and whatnot
        Mysql.flush_privileges()
Пример #11
0
    def restore(cls, basedir):
        dispatcher = Dispatcher.os_dispatcher()

        record_file = os.path.join(basedir, "service-asterisk.xml")

        # if files record file isn't found, simply return
        if not os.path.isfile(record_file):
            return

        # stop the service if already running
        if dispatcher.service_running(Asterisk.DAEMON):
            dispatcher.stop_service(Asterisk.DAEMON)

        # read files from the record file
        record = FilesRecordFile(record_file)
        sfiles = record.read()

        # restore those to their original locations
        for sfile in sfiles:
            sfile.copy_to(path_prefix=basedir)

        # start the service
        dispatcher.start_service(Asterisk.DAEMON)
Пример #12
0
    def backup(self, basedir):
        dispatcher = Dispatcher.os_dispatcher()
        null = open(OSUtils.null_file(), 'w')
                
        if OS.is_linux():
            Postgresql.set_root_pass()
        
        # check to see if service is running
        already_running = dispatcher.service_running(Postgresql.DAEMON)

        # start the postgresql server
        dispatcher.start_service(Postgresql.DAEMON)

        # get env containing postgres password
        penv = Postgresql.set_pgpassword_env()

        outfile = file(basedir + "/dump.psql", "w")
        pipe = subprocess.Popen([Postgresql.PGDUMPALL_CMD, "--username", "postgres"],
                                env=penv, stdout=outfile, stderr=null)
        pipe.wait()

        # if postgresql was running b4hand, start up again
        if not already_running:
            dispatcher.stop_service(Postgresql.DAEMON)
Пример #13
0
    def backup(self, basedir):
        dispatcher = Dispatcher.os_dispatcher()
        null = open(OSUtils.null_file(), 'w')

        if OS.is_linux():
            Mysql.set_root_pass()

        mysql_password = snap.config.options.service_options['mysql_password']

        # check to see if service is running
        already_running = dispatcher.service_running(Mysql.DAEMON) 

        # start the mysql server
        dispatcher.start_service(Mysql.DAEMON)

        # use a pipe to invoke mysqldump and capture output
        outfile = file(basedir + "/dump.mysql", "w")
        popen = subprocess.Popen([Mysql.MYSQLDUMP_CMD, "-u", "root", "-p" + mysql_password, "--all-databases"],
                                 stdout=outfile, stderr=null)
        popen.wait()

        # if mysql was stopped b4hand, start up again
        if not already_running:
            dispatcher.stop_service(Mysql.DAEMON)