Exemplo n.º 1
0
    def build_config(self):
        log.trace("build_config")
        #store1 = FTPStore("teststore1", "4MB", True, "localhost", "store1", "ftpuser", "ftpuserX9", False)
        #store2 = FTPStore("teststore2", "4MB", True, "localhost", "store2", "ftpuser", "ftpuserX9", False)
        if self.options.store:
            store1 = self.config.storage[self.options.store].copy()
            store2 = store1
        else:
            #    Make the store about 3x the options size
            s, dummy, dummy = utils.from_readable_form(self.options.size)
            store_size = utils.readable_form(s * 3)
            store1 = FolderStore("teststore1", store_size, True, os.path.join(self.store_folder, "teststore1"))
            store2 = FolderStore("teststore2", store_size, True, os.path.join(self.store_folder, "teststore2"))
            self.config.storage[store1.name] = store1
            self.config.storage[store2.name] = store2

        backup1 = Backup("testbackup1")
        backup1.include_folders = [self.files_folder]
        backup1.include_packages = True
        backup1.exclude_types = ["Music"]
        backup1.exclude_patterns = []
        backup1.store = store1.name
        backup1.notify_msg = False
        self.config.backups[backup1.name] = backup1

        backup2 = Backup("testbackup2")
        backup2.include_folders = [self.files_folder]
        backup2.include_packages = True
        backup2.exclude_patterns = []
        backup1.exclude_types = ["Videos", "Programs"]
        backup2.store = store2.name
        backup2.notify_msg = False
        self.config.backups[backup2.name] = backup2
Exemplo n.º 2
0
def wiz_execute(wiz):
    log.debug("Executing backup creation wizard")
    config = Config.get_config()    
    name = wiz.fields["name"].value
    path = wiz.fields["folderpath"].value
    excl = []
    for typ in config.file_types.iterkeys():
        if wiz.fields['excl-'+typ].value:
            excl.append(typ)
    store = wiz.fields["store"].value
    
    b = Backup(name)
    b.active = True
    b.include_folders = [path]
    b.include_packages = True
    b.exclude_types = excl
    b.store = store
    b.excrypt = False
    b.sched_type = "daily/weekly"
    b.sched_times = "19:00/Sun"    
    b.verify = False
    b.notify_msg = True
    b.notify_email = False
    b.shutdown_after = False
    
    config.backups[name] = b
    config.save()
    update_crontab(config.backups)
    
    

    dlg.Info(wiz, _("Your backup has been successfully created."))
    app.broadcast_update()
Exemplo n.º 3
0
    def testAutoManagementOfStore1(self):
        #    Run a set of backups that will overload the store. 
        #    The automanaged store should continue to archive old backups as required.
        #    Store space reclaimation happens across all backups (i.e. any run).
        #    We should see older runs from the first backup disappear.
        max_size, dummy, dummy = self.store.limit_details()

        filesize = utils.du(self.backup.include_folders[0])

        #    Lets make sure we are going to do enough backups that
        #    the older ones will be removed.
        RunCount = (max_size // filesize) + 2


        last_start = None
        for cycle in xrange(RunCount):
            if last_start:
                #    Make sure we have ticked to another second since the start of the last backup.
                while datetime.now() - last_start < timedelta(seconds=1):
                    time.sleep(0.01)

            backup = Backup(self.backup.name + str(cycle))
            backup.include_folders = self.backup.include_folders
            backup.store = self.backup.store
            backup.notify_msg = False
            self.config.backups[backup.name] = backup

            #    Run a full backup
            b = Run(backup.name, const.FullBackup, self.options)
            b.run()
            last_start = b.start_time

            #    Assert that the store is still of an appropriate size
            size, used, avail = self.store.current_usage()
            self.assertTrue(avail >= 0)
            self.assertTrue(used <= max_size)

            #    Confirm that's true on disk
            disksize = utils.du(self.store.root)
            self.assertTrue(disksize <= max_size)


        #    Check that some runs have actually been deleted
        runs = self.db.runs(self.backup.name + "0")
        self.assertTrue(len(runs) == 0)
        runs = self.db.runs(self.backup.name + "1")
        self.assertTrue(len(runs) == 0)
Exemplo n.º 4
0
    def save(self):
        #    BUILD THE BACKUP
        if len(self.txtName.GetValue()) == 0:
            raise Exception(_("Backup name cannot be blank"))
        if self.chkEncrypt.GetValue() and not self.config.data_passphrase:
            raise Exception(_("You cannot select encryption when the passphrase is blank (see Configuration page)."))
        if self.txtName.GetValue() == EmptyName:
            raise Exception(_("You need to provide a proper backup name"))
        try:
            #    Create the new backup object
            b = Backup(self.txtName.GetValue())
            #    General Information
            b.active = self.chkActive.GetValue()

            #    Folder Information
            b.include_folders = self.text_to_list(self.txtFolders.GetValue())
            b.include_packages = self.chkPackages.GetValue()

            #    Exclusions
            b.exclude_types = list(self.lstExcludeTypes.GetCheckedStrings()) # returns a tuple, convert to array
            b.exclude_patterns = self.text_to_list(self.txtExcludePatterns.GetValue())

            #    Destination
            b.store = self.cboStore.GetStringSelection()
            b.encrypt = self.chkEncrypt.GetValue()
            b.verify = self.chkVerify.GetValue()

            #    Schedule
            if self.radSchedAdvanced.GetValue():
                b.sched_type = "custom"
                b.sched_times = "%s\n%s" % (self.txtCronIncr.GetValue(), self.txtCronFull.GetValue())
            else:
                if self.radSchedDailyWeekly.GetValue():
                    b.sched_type = "daily/weekly"
                    time = self.cboTime1.GetStringSelection()
                    day = self.cboDay1.GetStringSelection()
                elif self.radSchedDailyMonthly.GetValue():
                    b.sched_type = "daily/monthly"
                    time = self.cboTime2.GetStringSelection()
                    day = self.cboMonthDay2.GetStringSelection()
                elif self.radSchedHourlyWeekly.GetValue():
                    b.sched_type = "hourly/weekly"
                    time = self.cboTime3.GetStringSelection()
                    day = self.cboDay3.GetStringSelection()
                elif self.radSchedNoneDaily.GetValue():
                    b.sched_type = "none/daily"
                    time = self.cboTime4.GetStringSelection()
                    day = "*"
                elif self.radSchedNoneWeekly.GetValue():
                    b.sched_type = "none/weekly"
                    time = self.cboTime5.GetStringSelection()
                    day = self.cboDay5.GetStringSelection()
                else:
                    raise Exception(_("Corrupt backup"))

                b.sched_times = time + "/" + day

            #    Notifications
            b.notify_msg = self.chkNotifyMsg.GetValue()
            b.notify_email = self.chkNotifyEmail.GetValue()
            b.shutdown_after = self.chkShutdown.GetValue()

            b.check()
        except Exception as e:
            raise e
        if self.state == ViewState:
            #    Delete the old name
            oldname = self.lstItems.GetStringSelection()
            try:
                del self.config.backups[oldname]
            except:
                pass
        self.config.backups[b.name] = b
        self.config.save()
        self.update_backup_list()

        #    Attempt to save the crontab. If this fails, the backup was corrupt.
        #    But it has been saved. So that is a problem
        update_crontab(self.config.backups)
Exemplo n.º 5
0
def build_config(conf):
    #    This is called to build a default config object
    #    It is used the first time this application is run.
    log.info("Building new config object")

    conf.version = 1
    conf.file_types = {_("Images"): ["jpg", "jpeg", "raw",
                                     "cr2", "png", "gif", "dng", "tiff",
                                        "tif", "bmp", "svg", "ppm", "psd"],
                     _("Videos"): ["avi", "mpg", "mpeg", "mp4", "mov", "m4v", "vob", "wmv", "flv"],
                     _("Music"): ["mp3", "aac", "ogg", "flac", "wav", "wma", "mpa"],
                     _("Programs"): ["bin", "dll", "exe", "com", "lib"]
                     }

    conf.storage = {}
    store = FolderStore(_("System Backup Folder"), "", False, os.path.join(const.DataDir, "vault-store"))
    conf.storage[store.name] = store

    #    By default, the data passphrase is blank.
    conf.data_passphrase = None

    conf.backups = {}
    
    b = Backup(_("Home"))
    b.include_folders = ["/home"]
    b.active = False
    b.include_packages = True
    b.store = store.name
    b.notify_msg = True
    conf.backups[b.name] = b

    conf.mail_server = ""
    conf.mail_port = 25
    conf.mail_ssl = False
    conf.mail_auth = False
    conf.mail_login = ""
    conf.mail_password = ""
    conf.mail_from = ""
    conf.mail_to = ""


    if const.Debug:

        #    If we are debugging, we create debug store and backup objects
        store = FolderStore("TestStore", "20MB", True,
                        os.path.join(const.RunDir, "store"))
        conf.storage[store.name] = store


        b = Backup("test")
        b.include_folders = [os.path.join(const.RunDir, "files")]
        b.include_packages = True
        b.exclude_types = ["Videos", "Programs"]
        b.exclude_patterns = ["*/not"]
        b.store = store.name
        b.notify_msg = True
        b.encrypt = True
        conf.backups[b.name] = b

        #    DEBUG - reset the store and include folders
        conf.backups["Home"].store = store.name
        conf.backups["Home"].include_folders = [os.path.join(const.RunDir, "files")]