Ejemplo n.º 1
0
def option_backup(**kwargs):
    """
    The code run when the backup argument is given. This will pass the configuration to the backup module
    to run the backup process.
    :param kwargs: A dictionary of arguments. This expects 'config' as a valid configuration.
    """
    backup.run_backup(kwargs["config"])
Ejemplo n.º 2
0
Archivo: ddu.py Proyecto: tgphelps/ddu
def main() -> None:
    args = docopt.docopt(__doc__, version=VERSION)
    logging.basicConfig(filename=LOG_FILE, filemode='a',
                        format='%(levelname)s - %(message)s', level=LOG_LEVEL)
    now = time.asctime()
    logging.info(f'log start: {now}')
    logging.info(f'args: {args}')

    repo_file = args['REPO']
    if args['create']:
        Repo.create(repo_file)
    elif args['verify']:
        repos = Repo(repo_file)
        logging.info(f'Verifying repo {repo_file}')
        n = 0
        if args['--hashes']:
            repos.verify_all_hashes(delete=args['-d'])
            n += 1
        if args['--backups']:
            repos.verify_backups()
            n += 1
        if args['--orphans']:
            repos.find_orphans(delete=args['-d'])
            n += 1
        if n == 0:
            util.msg('You must use --hashes, --backups, or --orphans')
    elif args['unlock']:
        # XXX Could this be: Repo(repo_file).unlock() ?
        repos = Repo(repo_file)
        repos.unlock()
    elif args['backup']:
        arg_prefix = args['--prefix']
        prefix = arg_prefix if arg_prefix else 'backup'
        if not alphanum.match(prefix):
            util.fatal('prefix must be alphanumeric')
        want_verify = args['--verify']
        backup.run_backup(args['--repo'], prefix, args['FILE'],
                          verify=want_verify,
                          verbose=args['-v'])
    elif args['restore']:
        restore.restore(repo_file)

    now = time.asctime()
    logging.info(f'log end: {now}')
def menu_option_backup(config):
    """
    The code that is run when the menu option for backing up the selected files is selected.
    This will ask for confirmation before beginning, and then run the backup process.
    :param config: The current backup configuration.
    """
    # Do not continue if one of the paths in the configuration no longer exists
    if not config.all_paths_are_valid():
        print(
            "At least one of the input or output paths in this configuration is no longer valid."
        )
        print(
            "Please ensure all relevant drives are plugged in, or edit any invalid paths."
        )
    else:
        # If this configuration is new or was modified, ask to save it
        if config.name is None:
            save_input = input(
                "Your configuration has not been saved yet. Would you like to save it? (y/n): "
            )
            if save_input.lower() == "y":
                menu_option_save(config)
        elif configuration.config_was_modified(config):
            save_input = input(
                "This configuration has changed since it was last saved. " +
                "Would you like to update it? (y/n): ")
            if save_input.lower() == "y":
                configuration.save_config(config, config.name)

        # Ask to confirm if this is ok to backup
        backup_confirmation = input(
            "Would you like to start the backup with this configuration? (y/n): "
        )
        # If yes, run the backup
        if backup_confirmation.lower() == "y":
            backup.run_backup(config)
Ejemplo n.º 4
0
 def do_backup(self):
     """Upload a database backup."""
     if self.backup_url:
         now = datetime.now()
         now_date = now.date()
         # Do a full backup right after midnight
         full = now_date != self.last_full
         # Insist on an incremental backup at least every 30 minutes,
         # but don't send a backup of less than 12 lines.
         min_size = 12 if now-self.last_incr < timedelta(minutes=30) else 0
         if backup.run_backup(self.dbfile,
                              self.backup_url, self.backup_auth,
                              full_backup=full, min_size=min_size):
             # The backup was not skipped (occured or no changes)
             self.last_incr = now
             if full:
                 self.last_full = now_date
 def handle_noargs(self, **options):
     print run_backup()
 async def run_backup(self):
     """
     Start the run_backup() asyncio task.
     """
     backup.run_backup(self.config)
import os
import time
import schedule
from backup import run_backup

if __name__ == '__main__':
    # Run the backup once at startup
    run_backup()

    # Run the backup every day at 7:05 PM
    schedule.every().day.at("19:05").do(run_backup)

    while True:
        # Check if it's time to run any schedules
        schedule.run_pending()
        time.sleep(60)
Ejemplo n.º 8
0
	def handle_noargs(self, **options):
			print run_backup()