def __get_rsync_backups (self): # get rsync backup dir self.rsyncsmf = rsyncsmf.RsyncSMF("%s:rsync" %(plugin.PLUGINBASEFMRI)) rsyncBaseDir = self.rsyncsmf.get_target_dir() sys,nodeName,rel,ver,arch = os.uname() self.rsyncDir = os.path.join(rsyncBaseDir, rsyncsmf.RSYNCDIRPREFIX, nodeName) if not os.path.exists(self.rsyncDir): return rootBackupDirs = [] for root, dirs, files in os.walk(self.rsyncDir): if '.time-slider' in dirs: dirs.remove('.time-slider') backupDir = os.path.join(root, rsyncsmf.RSYNCDIRSUFFIX) if os.path.exists(backupDir): insort(rootBackupDirs, os.path.abspath(backupDir)) for dirName in rootBackupDirs: os.chdir(dirName) for d in os.listdir(dirName): if os.path.isdir(d) and not os.path.islink(d): s1 = dirName.split ("%s/" % self.rsyncDir, 1) s2 = s1[1].split ("/%s" % rsyncsmf.RSYNCDIRSUFFIX, 1) fs = s2[0] rb = RsyncBackup ("%s/%s" %(dirName, d), self.rsyncDir, fs, d, os.stat(d).st_mtime) self.rsynced_backups.append (rb)
def __init__(self, icon, menu): Note.__init__(self, icon, menu) dbus.bus.NameOwnerWatch(bus, "org.opensolaris.TimeSlider.plugin.rsync", self._watch_handler) self.smfInst = rsyncsmf.RsyncSMF("%s:rsync" \ % (plugin.PLUGINBASEFMRI)) self._lock = threading.Lock() self._masterKey = None sysName, self._nodeName, rel, ver, arch = os.uname() # References to Gio.File and handler_id of a registered # monitor callback on Gio.File self._fm = None self._fmID = None # References to Gio.VolumeMonitor and handler_ids of # registered mount-added and mount-removed callbacks. self._vm = None self._vmAdd = None self._vmRem = None # Every time the rsync backup script runs it will # register with d-bus and trigger self._watch_handler(). # Use this variable to keep track of it's running status. self._scriptRunning = False self._targetDirAvail = False self._syncNowItem = Gtk.MenuItem(_("Update Backups Now")) self._syncNowItem.set_sensitive(False) self._syncNowItem.connect("activate", self._sync_now) self._menu.append(self._syncNowItem) self.refresh()
def __init_from_mp(self, mountpoint): self.rsyncsmf = rsyncsmf.RsyncSMF("%s:rsync" % (plugin.PLUGINBASEFMRI)) rsyncBaseDir = self.rsyncsmf.get_target_dir() sys, nodeName, rel, ver, arch = os.uname() self.rsync_dir = os.path.join(rsyncBaseDir, rsyncsmf.RSYNCDIRPREFIX, nodeName) self.mountpoint = mountpoint s1 = mountpoint.split("%s/" % self.rsync_dir, 1) s2 = s1[1].split("/%s" % rsyncsmf.RSYNCDIRSUFFIX, 1) s3 = s2[1].split('/', 2) self.fsname = s2[0] self.snaplabel = s3[1] self.creationtime = os.stat(mountpoint).st_mtime
backupTrashDir = os.path.join(self.rsync_dir, self.fsname, rsyncsmf.RSYNCTRASHSUFFIX, self.snaplabel) # move then delete os.rename(self.mountpoint, backupTrashDir) shutil.rmtree(backupTrashDir) log = "%s/%s/%s/%s/%s.log" % (self.rsync_dir, self.fsname, rsyncsmf.RSYNCDIRSUFFIX, ".partial", self.snaplabel) if os.path.exists(log): os.unlink(log) lockFp.close() os.unlink(lockFile) backupDirs = [] for root, dirs, files in os.walk( rsyncsmf.RsyncSMF("%s:rsync" % (plugin.PLUGINBASEFMRI)).get_target_dir()): if '.time-slider' in dirs: dirs.remove('.time-slider') backupDir = os.path.join(root, rsyncsmf.RSYNCDIRSUFFIX) if os.path.exists(backupDir): insort(backupDirs, os.path.abspath(backupDir)) print(backupDirs)
def run(self): self.mounts = self.__get_fs_mountpoints() self.rsyncsmf = rsyncsmf.RsyncSMF("%s:rsync" %(plugin.PLUGINBASEFMRI)) self.__get_rsync_backups () self.rescan()