コード例 #1
0
    def bkDatabase(self, widgt, event):
        '''
		即时备份操作,需要用户输入保存到的容器名。
		'''
        self.statusbar.get_context_id('backInfo')
        self.statusbar.push(0, "备份数据库")

        print self.serInfo
        conndb = ConnDatabase(self.serInfo)
        connStor = ConnStorage(self.serInfo)
        (result, bakfilepath) = conndb.conn.bk_now()
        if result:
            dial = self.builder.get_object('dialogContainerName')
            conName = self.builder.get_object('entryContainer')
            self.response = dial.run()
            dial.hide()
            if conName.get_text() != '':
                connStor.upload_file(conName.get_text(), bakfilepath)
                self.statusbar.get_context_id('backInfo')
                self.statusbar.push(0, "数据库备份成功")
            else:
                self.statusbar.get_context_id('backInfo')
                self.statusbar.push(0, "未能获取指定的容器名")
        else:
            self.statusbar.get_context_id('backInfo')
            self.statusbar.push(0, "数据库备份失败")

        self.connStorage(widgt, event)
コード例 #2
0
    def on_buttonDelStor1_clicked(self, object, data=None):
        connStor = ConnStorage(self.serInfo)
        if self.storInfo['objname'] is None:
            connStor.delete_container(self.storInfo['conname'])
        else:
            connStor.delete_object(self.storInfo['conname'],
                                   self.storInfo['objname'])

        self.connStorage(object, data)
コード例 #3
0
    def incr_bak(self, serConf, bakcontainer):
        '''
		负责执行一次增量备份,将备份文件上传至云存储。
		'''
        conndb = ConnDatabase(serConf)
        connStor = ConnStorage(serConf)
        (result, bakfilepath) = conndb.conn.incr_bak()
        if result:
            connStor.upload_file(bakcontainer, bakfilepath)
        else:
            print 'increase backup error!'
コード例 #4
0
 def on_buttonSaveObj_clicked(self, object, data=None):
     connStor = ConnStorage(self.serInfo)
     dest_path = self.dialogFile.get_current_folder()
     if self.storInfo['objname'] is None:
         # 不提供针对整个容器的下载
         #            connStor.download_container(self.storInfo['conname'], dest_path)
         pass
     else:
         connStor.download_object(self.storInfo['conname'],
                                  self.storInfo['objname'], dest_path)
     self.dialogFile.hide()
コード例 #5
0
    def glob_bak(self, serConf, bakcontainer):
        '''
		负责执行一次全局备份,将备份文件上传至云存储。
		'''
        timestr = time.strftime(r"%Y-%m-%d_%H-%M-%S", time.localtime())
        print timestr
        conndb = ConnDatabase(serConf)
        connStor = ConnStorage(serConf)
        (result, bakfilepath) = conndb.conn.glob_bak()
        if result:
            connStor.upload_file(bakcontainer, bakfilepath)
        else:
            print 'global backup error!'
コード例 #6
0
    def headStor(self, widgt, event):
        '''
		获取云存储容器或对象的详细信息
		'''
        print self.serInfo
        connStor = ConnStorage(self.serInfo)
        if self.storInfo['objname'] is None:
            info = connStor.head_container(self.storInfo['conname'])
        else:
            info = connStor.head_object(self.storInfo['conname'],
                                        self.storInfo['objname'])
        info_str = " "
        for key, value in info.items():
            info_str += key + " : " + str(value) + "\n"
        self.warnDial.set_markup(info_str)
        self.response = self.warnDial.run()
        self.warnDial.hide()
コード例 #7
0
 def on_buttonRecover1_clicked(self, object, data=None):
     conndb = ConnDatabase(self.serInfo)
     connstor = ConnStorage(self.serInfo)
     if self.storInfo['objname'][0] is not None:
         if 'glob' in self.storInfo['objname'][0]:
             # 从全局备份恢复
             connstor.download_object(self.storInfo['conname'][0],
                                      self.storInfo['objname'][0],
                                      conndb.conn.bkdir)
             conndb.conn.recover_glob(conndb.conn.bkdir + "/" +
                                      self.storInfo['objname'][0])
         elif 'incr' in self.storInfo['objname'][0]:
             # 从增量备份恢复
             timestop = float(connstor.head_object(self.storInfo['conname'][0], \
                self.storInfo['objname'][0]).get('x-timestamp'))
             dict_tmp = {}
             objlist = connstor.getContainerList(
                 self.storInfo['conname'][0])
             for objname in objlist:
                 if 'glob' in objname:
                     # 首先查找时间最近的一次全局备份
                     timestamp = float(connstor.head_object(self.storInfo['conname'][0], \
                        objname).get('x-timestamp'))
                     dict_tmp[timestamp] = objname
             glob_bakfile = max(dict_tmp.itervalues(), key=lambda k: k)
             glob_timestamp = dict_tmp.keys()[dict_tmp.values().index(
                 glob_bakfile)]
             dict_tmp.clear()
             for objname in objlist:
                 if 'incr' in objname:
                     # 然后查找该全局备份后所有的增量备份,到选中的增量备份为止
                     timestamp = float(connstor.head_object(self.storInfo['conname'][0], \
                        objname).get('x-timestamp'))
                     if timestamp >= glob_timestamp and timestamp <= timestop:
                         dict_tmp[timestamp] = objname
             # timestamp_list = sorted(dict_tmp.iterkeys(), key=lambda k:k[0])
             # incr_bakfile_list = []
             # for item in timestamp_list:
             # incr_bakfile_list.append(timestamp_list[item])
             incr_bakfile_list = sorted(dict_tmp.itervaluse(),
                                        key=lambda k: k[0])
             conndb.conn.recover_glob(glob_bakfile)
             conndb.conn.recover_incr(incr_bakfile_list)
         else:
             print 'Unkown backup file type!'
コード例 #8
0
    def connStorage(self, widgt, event):
        '''
		连接云存储,并根据返回数据显示到云存储信息列表。
		'''
        print "display the storage file"
        self.popMemuServer.hide()
        connStor = ConnStorage(self.serInfo)

        if len(self.storTable.get_columns()) == 0:
            columnTree = gtk.TreeViewColumn()
            cell = gtk.CellRendererText()
            columnTree.pack_start(cell, True)
            columnTree.add_attribute(cell, "text", 0)
            self.storTable.insert_column(columnTree, 0)
        else:
            print self.storTable.get_columns()

        if self.storTable.get_model() == None:
            treeStore = gtk.TreeStore(str)
        else:
            treeStore = self.storTable.get_model()
            treeStore.clear()

        conList = connStor.getContainerList()
        for con in conList:
            #            conName = []
            #            conName.append(con)
            item = treeStore.append(None, [con])  # 这里的conName必须为列表
            objlist = connStor.getObjectList(con)
            for obj in objlist:
                treeStore.append(item, [obj])

        self.storTable.set_model(treeStore)
        self.notebookR.set_current_page(1)
        self.statusbar.get_context_id('storConnInfo')
        self.statusbar.push(0, "显示云存储内容")