コード例 #1
0
    def test_it_returns_the_latest_timestamped_file_with_ext(self):
        self.create_files(
            'default-2013-05-02-1367553089.sqlite.gz',
            'default-2013-06-06-1370570260.sqlite.gz',
            'default-2013-06-06-1370580510.sqlite.gz',
            'default-2013-05-02-1367553089.mysql.gz',
            'default-2013-06-06-1370570260.mysql.gz',
            'default-2013-06-06-1370580510.mysql.gz',
            'default-2013-05-02-1367553089.pgsql.gz',
            'default-2013-06-06-1370570260.pgsql.gz',
            'default-2013-06-06-1370580510.pgsql.gz',
        )

        sqlite_file = get_latest_timestamped_file('sqlite',
                                                  dir=self.SCRATCH_DIR)
        mysql_file = get_latest_timestamped_file('mysql', dir=self.SCRATCH_DIR)
        pgsql_file = get_latest_timestamped_file('pgsql', dir=self.SCRATCH_DIR)

        self.assertEqual(
            sqlite_file,
            self.get_path('default-2013-06-06-1370580510.sqlite.gz'))
        self.assertEqual(
            mysql_file,
            self.get_path('default-2013-06-06-1370580510.mysql.gz'))
        self.assertEqual(
            pgsql_file,
            self.get_path('default-2013-06-06-1370580510.pgsql.gz'))
コード例 #2
0
    def handle(self, *args, **options):
        super(Command, self).handle(*args, **options)

        # Django is querying django_content_types in a hanging transaction
        # Because of this psql can't drop django_content_types and just hangs
        close_connection()

        # Ensure backup dir present
        if not os.path.exists(BACKUP_DIR):
            raise CommandError(
                "Backup dir '{0}' does not exist!".format(BACKUP_DIR))

        backup_name = options['backup_name']
        drop_tables = options['drop_tables']
        show_output = options['show_output']

        # Loop through databases
        for db_name, db_config in settings.DATABASES.items():
            with section("Restoring '{0}'...".format(db_name)):
                # Get backup config for this engine type
                engine = db_config['ENGINE']
                backup_config = BACKUP_CONFIG.get(engine)
                if not backup_config:
                    raise SectionWarning(
                        "Restore for '{0}' engine not implemented".format(
                            engine))

                # Get backup file name
                backup_extension = backup_config['backup_extension']
                if backup_name:
                    backup_file = '{dir}/{db_name}-{backup_name}.{ext}.gz'.format(
                        dir=BACKUP_DIR,
                        db_name=db_name,
                        backup_name=backup_name,
                        ext=backup_extension,
                    )
                else:
                    try:
                        backup_file = get_latest_timestamped_file(
                            backup_extension)
                    except RestoreError as e:
                        raise SectionError(e)

                # Find restore command and get kwargs
                restore_func = backup_config['restore_func']
                restore_kwargs = {
                    'backup_file': backup_file,
                    'db_config': db_config,
                    'drop_tables': drop_tables,
                    'show_output': show_output,
                }

                # Run restore command
                try:
                    restore_func(**restore_kwargs)
                    logger.info(
                        "Restored '{db_name}' from '{backup_file}'".format(
                            db_name=db_name, backup_file=backup_file))
                except (RestoreError, CalledProcessError) as e:
                    raise SectionError(e)
コード例 #3
0
    def handle(self, *args, **options):
        super(Command, self).handle(*args, **options)

        # Django is querying django_content_types in a hanging transaction
        # Because of this psql can't drop django_content_types and just hangs
        close_connection()

        # Ensure backup dir present
        if not os.path.exists(BACKUP_DIR):
            raise CommandError("Backup dir '{0}' does not exist!".format(BACKUP_DIR))

        backup_name = options['backup_name']
        drop_tables = options['drop_tables']
        show_output = options['show_output']

        # Loop through databases
        for db_name, db_config in settings.DATABASES.items():
            with section("Restoring '{0}'...".format(db_name)):
                # Get backup config for this engine type
                engine = db_config['ENGINE']
                backup_config = BACKUP_CONFIG.get(engine)
                if not backup_config:
                    raise SectionWarning("Restore for '{0}' engine not implemented".format(engine))

                # Get backup file name
                backup_extension = backup_config['backup_extension']
                if backup_name:
                    backup_file = '{dir}/{db_name}-{backup_name}.{ext}.gz'.format(
                        dir=BACKUP_DIR,
                        db_name=db_name,
                        backup_name=backup_name,
                        ext=backup_extension,
                    )
                else:
                    try:
                        backup_file = get_latest_timestamped_file(backup_extension)
                    except RestoreError as e:
                        raise SectionError(e)

                # Find restore command and get kwargs
                restore_func = backup_config['restore_func']
                restore_kwargs = {
                    'backup_file': backup_file,
                    'db_config': db_config,
                    'drop_tables': drop_tables,
                    'show_output': show_output,
                }

                # Run restore command
                try:
                    restore_func(**restore_kwargs)
                    logger.info("Restored '{db_name}' from '{backup_file}'".format(
                        db_name=db_name,
                        backup_file=backup_file))
                except (RestoreError, CalledProcessError) as e:
                    raise SectionError(e)
コード例 #4
0
ファイル: files.py プロジェクト: fusionbox/django-backupdb
    def test_it_returns_the_latest_timestamped_file_with_ext(self):
        self.create_files(
            'default-2013-05-02-1367553089.sqlite.gz',
            'default-2013-06-06-1370570260.sqlite.gz',
            'default-2013-06-06-1370580510.sqlite.gz',

            'default-2013-05-02-1367553089.mysql.gz',
            'default-2013-06-06-1370570260.mysql.gz',
            'default-2013-06-06-1370580510.mysql.gz',

            'default-2013-05-02-1367553089.pgsql.gz',
            'default-2013-06-06-1370570260.pgsql.gz',
            'default-2013-06-06-1370580510.pgsql.gz',
        )

        sqlite_file = get_latest_timestamped_file('sqlite', dir=self.SCRATCH_DIR)
        mysql_file = get_latest_timestamped_file('mysql', dir=self.SCRATCH_DIR)
        pgsql_file = get_latest_timestamped_file('pgsql', dir=self.SCRATCH_DIR)

        self.assertEqual(sqlite_file, self.get_path('default-2013-06-06-1370580510.sqlite.gz'))
        self.assertEqual(mysql_file, self.get_path('default-2013-06-06-1370580510.mysql.gz'))
        self.assertEqual(pgsql_file, self.get_path('default-2013-06-06-1370580510.pgsql.gz'))