Esempio n. 1
0
    def BackupEntry(self):
        """Sync each source entries and backup partition (destination).

    Performs the initial sequential backup process. For each entry in the list
    enlist (entries mentioned in config file), backup process is run to sync
    the source and destination (backup partition)
    """

        if self.backupmethod == "RSYNC":
            self.ssh_shell_var = [
                self.ssh_path, self.sshport, self.sshuser, self.backupserver
            ]
        else:
            self.ssh_shell_var = None

        for entry in self.enlist:
            # Print appropriate messsages and perform an initial full backup.
            startbackup = backup.Backup(self.backupdirpath,
                                        self.rsync_path,
                                        self.exlist_tmpname,
                                        entry,
                                        log_handle=self.log,
                                        dryrun=self.log.dryrun,
                                        sh_var=self.ssh_shell_var)
            startbackup.VerifyBackup()
Esempio n. 2
0
def main():
    envse = [
        'GOOGLE_OAUTH_CLIENT', 'GOOGLE_OAUTH_SECRET', 'DISCORDBOT',
        'DISCORDBOT_TOKEN', 'BASE_URL', 'S3_BUCKET', 'S3_PREFIX'
    ]

    out = util.Output(logdir, util.environ_bool('DEBUG'))
    f = util.environ(envse, 'error')
    if f:
        out.error('error: some environment variables are not set. exiting.')
        sys.exit(1)
    if os.environ.get('ONESHOT') is None and (
            os.environ.get('SCHEDULE_TIME') is None
            or os.environ.get('SCHEDULE_WEEKDAY') is None):
        out.error(
            'error: environment variables ONESHOT or (SCHEDULE_TIME and SCHEDULE_WEEKDAY) must be set. exiting.'
        )
        sys.exit(1)

    os.makedirs(catalogdir, exist_ok=True)

    try:
        redirect_url = '{0}{1}'.format(os.environ['BASE_URL'], callback_url)
        cred = credential.Credential(out, os.environ['GOOGLE_OAUTH_CLIENT'],
                                     os.environ['GOOGLE_OAUTH_SECRET'],
                                     token_url, scope, redirect_url,
                                     authorization_base_url, tokendir)
        cb = callback.Callback(asyncio.new_event_loop(), out, cred,
                               callback_url)
        threading.Thread(target=cb.run, name='callback', daemon=True).start()

        album = util.environ_bool('ALBUM')
        library = util.environ_bool('LIBRARY')
        back = backup.Backup(out, cb, cred, os.environ['S3_BUCKET'],
                             os.environ['S3_PREFIX'], catalogdir, album,
                             library)

        if cred.load():
            out.info('using saved token')
        else:
            authorization_url = cred.authorization_step()
            out.message('Please authenticate the application: {0}'.format(
                authorization_url))
            cred.wait_authorization()
            out.info('main(): authorized, email={}'.format(cred.email))

        if util.environ_bool('ONESHOT'):
            back.run()
            out.info('main(): all tasks done')
        else:
            sched = Scheduler(None, out, back)
            sched.run()
            out.error('main(): scheduler down!')
    except Exception as e:
        out.exception('error: main', e)
async def main(args):
    datastore = []
    # Read the file passed by argument and break it into blobs
    with args.file as f:
        while True:
            blob = f.read(args.blob_size)
            if not blob:
                break
            # This loop is used to not break word in half
            while not str.isspace(blob[-1]):
                ch = f.read(1)
                if not ch:
                    break
                blob += ch
            logger.debug('Blob: %s', blob)
            datastore.append(blob)
    logger.debug('Size: ' + str(len(datastore)))

    coordinator = Coordinator(datastore)

    try:
        logger.info('Starting coordinator')
        loop = asyncio.get_event_loop()
        server = await loop.create_server(lambda: EchoProtocol(coordinator),
                                          args.host, args.port)
        await server.serve_forever()

    except:
        logger.info('Starting backup')
        backup_coord = backup.Backup(args.host, args.port, datastore)
        backup_coord.start_backup()

        # if coordinator dies
        message_backup = backup_coord.get_messages()
        elems = message_backup[0][0]
        index = message_backup[0][1]

        # backup is the new coordinator
        coordinator = Coordinator(datastore, index, elems)

        loop = asyncio.get_event_loop()
        server = await loop.create_server(lambda: EchoProtocol(coordinator),
                                          args.host, args.port)
        await server.serve_forever()
Esempio n. 4
0
def execute_swift_client(args):
    """

    Argument:
        args: argument object
    """
    (auth_url, username, password, rotate_limit,
     verify) = config.check_config(args.config)
    b = backup.Backup(auth_url, username, password, verify=verify)
    if args.list:
        # listing backup data
        backup_l = b.retrieve_backup_data_list(args.verbose)
        utils.list_data(backup_l)
    elif args.path:
        # backup data to swift
        b.backup(args.path)
    elif args.retrieve:
        # retrive backup data
        b.retrieve_backup_data(args.retrieve, args.output)
    elif args.delete:
        # delete backup data
        b.delete_backup_data(args.delete)
Esempio n. 5
0
    def load_cfg(self):
        # Load the config file
        with open(self.config_file, "r") as yamlfile:
            self.config = yaml.load(yamlfile)

        self.path = self.config["path"]
      
        if "backup_interval_mins" in self.config:
            self.backup_interval_mins = self.config["backup_interval_mins"]

        self.stdin_path = "/dev/null"
        self.stdout_path = os.path.join(self.path, "backupd.log")
        self.stderr_path = self.stdout_path
        self.pidfile_path = os.path.join(self.path, "backupd.pid")
        self.pidfile_timeout = 5

        self.backup_config = []
        if "backups" in self.config:
            self.backup_config = self.config["backups"]

        self.active_backups = []
        for config in self.backup_config:
            self.active_backups.append(backup.Backup(config))
Esempio n. 6
0
def take_snapshot():
    display = gtk.gdk.display_get_default()
    statusIcon = None

    if not display is None:
        gtk.gdk.threads_init()
        GTKMainThread().start()

        try:
            statusIcon = gtk.StatusIcon()
            statusIcon.set_from_stock(gtk.STOCK_SAVE)
            statusIcon.set_visible(True)
            statusIcon.set_tooltip(_("Back In Time: take snapshot ..."))
        except:
            pass

    backup.Backup().backup()

    if not statusIcon is None:
        statusIcon.set_visible(False)

    if not display is None:
        gtk.main_quit()
Esempio n. 7
0
###################################

elif mode == 'enableall':
    addon_able.setall_enable()

elif mode == 'teststuff':
    freshstart.remove_db()
#######################################
elif mode == 'backup_restore':
    backup.BACKUPMENU()

elif mode == 'full_backup':
    backup.FullBackup()

elif mode == 'small_backup':
    backup.Backup()

elif mode == 'do_backup_restore':
    backup.Restore()

elif mode == 'display_backup_settings':
    kodi.openSettings(addon_id, id1=0, id2=0)

elif mode == 'read_zip':
    backup.READ_ZIP(url)

elif mode == 'del_backup':
    backup.ListBackDel()

elif mode == 'do_del_backup':
    backup.DeleteBackup(url)
Esempio n. 8
0
def main(args):
    filename = args.filename

    # check for .hls or .hxb file

    b = backup.Backup(filename)
    b.read(debug=args.debug)

    doExport = False

    if args.x:
        # True = Success, False = Fail
        doExport = b.makeExportDir()
        #!print(doExport)

    if b.isFullBackup():
        # Print basic details by default
        b.printSummary()

        if args.global_settings:
            b.printGlobalSettings()

        if args.ir:
            if doExport:
                if args.i == 'all':
                    b.exportAllIRs()
                elif util.argIsList(args.i):
                    b.exportIRs(util.indexStringToList(args.i))
                else:
                    b.exportIR(int(args.i))
            else:
                if args.i == 'all':
                    b.printAllIRs()
                elif util.argIsList(args.i):
                    b.printIRs(util.indexStringToList(args.i))
                else:
                    b.printIR(int(args.i))

        if args.set_list:
            if doExport:
                if args.s == 'all':
                    b.exportAllSetLists()
                elif util.argIsList(args.s):
                    b.exportSetLists(util.indexStringToList(args.s))
                else:
                    b.exportSetList(int(args.s))
            else:
                if args.s == 'all':
                    b.printAllSetLists()
                elif util.argIsList(args.s):
                    b.printSetLists(util.indexStringToList(args.s))
                else:
                    b.printSetList(int(args.s))
    else:
        # A .hls file only has one set list?
        if args.set_list:
            if doExport:
                b.exportAllSetLists()
            else:
                b.printAllSetLists()

    if args.preset:
        if doExport:
            if args.p == 'all':
                b.exportAllPresets()
            elif util.argIsList(args.p):
                b.exportPresets(int(args.s), util.indexStringToList(args.p))
            else:
                if b.isFullBackup():
                    b.exportPreset(int(args.s), int(args.p))
                else:
                    b.exportPreset(1, int(args.p))
        else:
            if args.p == 'all':
                # should there be a printAllPresets function for consistency?
                b.printSetList(int(args.s))
            elif util.argIsList(args.p):
                b.printPresets(int(args.s), util.indexStringToList(args.p))
            else:
                if b.isFullBackup():
                    b.printPreset(int(args.s), int(args.p))
                else:
                    b.printPreset(1, int(args.p))
Esempio n. 9
0
import backup

my_backup = backup.Backup()
my_backup.run_backup()


Esempio n. 10
0
args = parser.parse_args()

defaults_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             "defaults.yml")

config = {}
for file in [defaults_file, "/etc/ovirt-backup/config.yml", args.config_file]:
    print("Loading config file {}".format(file))
    try:
        with open(file, "r") as c:
            backup.util.dict_merge(config, yaml.safe_load(c))
    except IOError as err:
        print("Failed to load {}. {}".format(file, err))
        pass

if args.show_config:
    pp = pprint.PrettyPrinter(indent=2)
    pp.pprint(config)
    exit()

logging.basicConfig(level=logging.DEBUG, filename=config['logs']['file'])
#logging.getLogger().addHandler(logging.StreamHandler())

b = backup.Backup(config)
b.search = args.search
b.umount = args.umount

b.add(backup.backends.ResticBackend(config["restic"]))
b.add(backup.backends.ClonezillaBackend(config["clonezilla"]))
b.backup()
Esempio n. 11
0
def initializeStorage(trezor, pwMap, settings):
    """
	Initialize new encrypted password file, ask for master passphrase.

	Initialize RSA keypair for backup, encrypt private RSA key using
	backup passphrase and Trezor's cipher-key-value system.

	Makes sure a session is created on Trezor so that the passphrase
	will be cached until disconnect.

	@param trezor: Trezor client
	@param pwMap: PasswordMap where to put encrypted backupKeys
	@param settings: Settings object to store password database location
	"""
    if settings.TArg:
        # Terminal mode
        print('Welcome to %s' % basics.NAME)
        print('You have to go through a one-time only initialization step. \n'
              'You will be asked 2 questions: a) the name of a file \n'
              'where to store the password database and b) a passphrase. \n'
              'The passphrase will be used with the Trezor to securely \n'
              'encrypt your passwords. If you lose the passphrase you will \n'
              'lose access to your password database. \n'
              'Do not lose it!')
        print('Give a filename where to store the password database? ')
        print('Warning: If file exists it will be overwritten. ')
        print(
            'Note: There is no shell expansion, so do not use anything like ~, $HOME, $VAR, etc. '
        )
        print('')
        while True:
            pwFileName = utils.input23(
                u"Filename where to store the password database? ")
            try:
                open(pwFileName, 'wb+').close()
            except OSError as e:
                print(
                    '%s is not a valid filename, it cannot be opened for writing. '
                    'Try again. (%s)' % (pwFileName, e))
            else:
                break
        print('Ok, the password database will be stored in %s' % (pwFileName))
        if settings.PArg is not None and settings.PArg != '' and settings.NArg:
            print(
                'The passphrase was specified in the comand line, hence no need to ask.'
            )
            masterPassphrase1 = settings.PArg
        else:
            print(
                'For safety you will now be asked twice for the passphrase. ')
            while True:
                # read passphrase from stdin
                try:
                    masterPassphrase1 = getpass.getpass(
                        u"Please enter passphrase: ")
                    masterPassphrase1 = normalize_nfc(masterPassphrase1)
                except KeyboardInterrupt:
                    sys.stderr.write(
                        u"\nKeyboard interrupt: passphrase not read. Aborting.\n"
                    )
                    sys.exit(3)
                except Exception as e:
                    sys.stderr.write(
                        u"Critical error: Passphrase not read. Aborting. (%s)"
                        % e)
                    sys.exit(3)
                # read passphrase from stdin
                try:
                    masterPassphrase2 = getpass.getpass(
                        u"Please repeat passphrase: ")
                    masterPassphrase2 = normalize_nfc(masterPassphrase2)
                except KeyboardInterrupt:
                    sys.stderr.write(
                        u"\nKeyboard interrupt: passphrase not read. Aborting.\n"
                    )
                    sys.exit(3)
                except Exception as e:
                    sys.stderr.write(
                        u"Critical error: Passphrase not read. Aborting. (%s)"
                        % e)
                    sys.exit(3)
                if masterPassphrase1 == masterPassphrase2:
                    break
                else:
                    print(
                        'The two passphrases provided do not match. Try again.'
                    )
        masterPassphrase = masterPassphrase1
    else:
        # GUI mode
        dialog = InitializeDialog()
        if settings.passphrase() is not None:
            dialog.setPw1(settings.passphrase())
            dialog.setPw2(settings.passphrase())

        if not dialog.exec_():
            sys.exit(4)

        masterPassphrase = dialog.pw1()
        pwFileName = dialog.pwFile()
    trezor.prefillPassphrase(masterPassphrase)
    backupkey = backup.Backup(trezor, noconfirm=settings.NArg)
    backupkey.generate()
    pwMap.backupKey = backupkey
    settings.dbFilename = pwFileName
    settings.FArg = pwFileName
    settings.store()
    # write the file with no user data to the disk
    # to make the master passphrase permanent
    pwMap.save(pwFileName)
Esempio n. 12
0
    def backup_zsh_config(self):
        self.log.print('Backing up zsh config', ll.Info)

        b = backup.Backup(log)

        self.log.print('Done', ll.Debug)
Esempio n. 13
0
    def __init__(self):
        self.backup = backup.Backup()
        self.config = self.backup.config
        self.specialBackgroundColor = 'lightblue'

        self.glade = gtk.glade.XML(self.config.gladeFile(), None, 'backintime')

        signals = {
            'on_MainWindow_destroy': gtk.main_quit,
            'on_MainWindow_delete_event': self.on_close,
            'on_btnExit_clicked': self.on_close,
            'on_btnAbout_clicked': self.on_btnAbout_clicked,
            'on_btnSettings_clicked': self.on_btnSettings_clicked,
            'on_btnBackup_clicked': self.on_btnBackup_clicked,
            'on_btnRestore_clicked': self.on_btnRestore_clicked,
            'on_listPlaces_cursor_changed': self.on_listPlaces_cursor_changed,
            'on_listTimeLine_cursor_changed':
            self.on_listTimeLine_cursor_changed,
            'on_btnFolderUp_clicked': self.on_btnFodlerUp_clicked,
            'on_listFolderView_row_activated':
            self.on_listFolderView_row_activated
        }

        self.glade.signal_autoconnect(signals)

        self.window = self.glade.get_widget('MainWindow')
        self.window.set_title(self.config.APP_NAME)

        #icons
        self.iconNames = IconNames()

        #fix a glade bug
        self.glade.get_widget('btnCurrentPath').set_expand(True)

        #status bar
        self.statusBar = self.glade.get_widget('statusBar')
        self.statusBar.push(0, _('Done'))

        #setup places view
        self.listPlaces = self.glade.get_widget('listPlaces')

        pixRenderer = gtk.CellRendererPixbuf()
        textRenderer = gtk.CellRendererText()

        column = gtk.TreeViewColumn(_('Places'))
        column.pack_start(pixRenderer, False)
        column.pack_end(textRenderer, True)
        column.add_attribute(pixRenderer, 'icon-name', 2)
        column.add_attribute(textRenderer, 'markup', 0)
        column.set_cell_data_func(pixRenderer, self.placesPixRendererFunction,
                                  None)
        column.set_cell_data_func(textRenderer,
                                  self.placesTextRendererFunction, None)
        #column.set_alignment( 0.5 )
        self.listPlaces.append_column(column)

        self.storePlaces = gtk.ListStore(str, str, str)
        self.listPlaces.set_model(self.storePlaces)
        self.listPlaces.get_selection().set_select_function(
            self.placesSelectFunction, self.storePlaces)

        #setup folder view
        self.listFolderView = self.glade.get_widget('listFolderView')

        pixRenderer = gtk.CellRendererPixbuf()
        textRenderer = gtk.CellRendererText()

        column = gtk.TreeViewColumn(_('Name'))
        column.pack_start(pixRenderer, False)
        column.pack_end(textRenderer, True)
        #column.add_attribute( pixRenderer, 'stock-id', 2 )
        column.add_attribute(pixRenderer, 'icon-name', 2)
        column.add_attribute(textRenderer, 'markup', 0)
        column.set_expand(True)
        column.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)
        #column.set_alignment( 0.5 )
        #self.lblTime = gtk.Label()
        #self.lblTime.set_markup( "<b>%s</b>" % "Now" )
        #self.lblTime.show()
        #column.set_widget( self.lblTime )
        self.listFolderView.append_column(column)

        textRenderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn(_('Size'))
        column.pack_end(textRenderer, True)
        column.add_attribute(textRenderer, 'markup', 4)
        #column.set_alignment( 0.5 )
        self.listFolderView.append_column(column)

        textRenderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn(_('Date'))
        column.pack_end(textRenderer, True)
        column.add_attribute(textRenderer, 'markup', 5)
        #column.set_alignment( 0.5 )
        self.listFolderView.append_column(column)

        self.storeFolderView = gtk.ListStore(str, str, str, int, str, str)
        self.listFolderView.set_model(self.storeFolderView)

        #setup timeline view
        self.listTimeLine = self.glade.get_widget('listTimeLine')

        textRenderer = gtk.CellRendererText()

        column = gtk.TreeViewColumn(_('Timeline'), textRenderer, markup=0)
        column.set_cell_data_func(textRenderer,
                                  self.placesTextRendererFunction, None)
        #column.set_alignment( 0.5 )
        self.listTimeLine.append_column(column)

        self.storeTimeLine = gtk.ListStore(str, str)
        self.listTimeLine.set_model(self.storeTimeLine)
        self.listTimeLine.get_selection().set_select_function(
            self.placesSelectFunction, self.storeTimeLine)
        self.updateTimeLine = False

        #calculate specialBackgroundColor
        style = self.listTimeLine.get_style()
        bg1 = style.bg[gtk.STATE_NORMAL]
        bg2 = style.bg[gtk.STATE_SELECTED]
        self.specialBackgroundColor = gtk.gdk.Color(
            (2 * bg1.red + bg2.red) / 3, (2 * bg1.green + bg2.green) / 3,
            (2 * bg1.blue + bg2.blue) / 3).to_string()

        #restore size & position
        if self.config.MAIN_WINDOW_X >= 0 and self.config.MAIN_WINDOW_Y >= 0:
            self.window.move(self.config.MAIN_WINDOW_X,
                             self.config.MAIN_WINDOW_Y)

        if self.config.MAIN_WINDOW_WIDTH > 0 and self.config.MAIN_WINDOW_HEIGHT > 0:
            self.window.resize(self.config.MAIN_WINDOW_WIDTH,
                               self.config.MAIN_WINDOW_HEIGHT)

        if self.config.MAIN_WINDOW_HPANED1_POSITION > 0 and self.config.MAIN_WINDOW_HPANED2_POSITION > 0:
            self.glade.get_widget('hpaned1').set_position(
                self.config.MAIN_WINDOW_HPANED1_POSITION)
            self.glade.get_widget('hpaned2').set_position(
                self.config.MAIN_WINDOW_HPANED2_POSITION)

        self.aboutDialog = AboutDialog(self.config, self.glade)
        self.settingsDialog = settingsdialog.SettingsDialog(
            self.config, self.glade)

        self.window.show()

        #set window handle in pid file
        file = open(self.config.pidFile(), 'at')
        file.write(";%s" % str(self.window.window.xid))
        file.close()

        gobject.timeout_add(100, self.onInit)
Esempio n. 14
0
        if raw_upload_path:
            print fmt_title("Executing Duplicity to backup %s to %s" % (raw_upload_path, target.address))

            _print("export PASSPHRASE=$(cat %s)" % conf.secretfile)
            uploader = duplicity.Uploader(True,
                                          conf.volsize,
                                          conf.full_backup,
                                          conf.s3_parallel_uploads)
            uploader(raw_upload_path, target, force_cleanup=not opt_resume, dry_run=opt_simulate, debug=opt_debug,
                     log=_print)

        else:
            hooks.backup.pre()
            b = backup.Backup(registry.profile,
                              conf.overrides,
                              conf.backup_skip_files, conf.backup_skip_packages, conf.backup_skip_database,
                              opt_resume, True, dump_path if dump_path else "/")

            hooks.backup.inspect(b.extras_paths.path)

            if dump_path:
                b.dump(dump_path)
            else:
                print "\n" + fmt_title("Executing Duplicity to backup system changes to encrypted, incremental archives")
                _print("export PASSPHRASE=$(cat %s)" % conf.secretfile)

                uploader = duplicity.Uploader(True,
                                              conf.volsize,
                                              conf.full_backup,
                                              conf.s3_parallel_uploads,
                                              includes=[ b.extras_paths.path ],
Esempio n. 15
0
 def setUp(self):
     self.backup = backup.Backup(mock.MagicMock(), mock.MagicMock())