backup_project.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:django-green-grove 作者: dreipol 项目源码 文件源码
def back_up_database(self, backup_storage, temp_backup_path):
        logger.info('Start backing up the database.')
        file_path = '{database}_{timestamp}.dump'.format(
            database=settings.DATABASES['default']['NAME'],
            timestamp=self.timestamp
        )
        temp_file_path = '{backup_path}/{file_path}'.format(backup_path=temp_backup_path, file_path=file_path)

        # Run the `pg_dump` command.
        os.system('pg_dump -h {host} -U {user} {database} > {file_path}'.format(
            host=settings.DATABASES['default']['HOST'],
            user=settings.DATABASES['default']['USER'],
            database=settings.DATABASES['default']['NAME'],
            file_path=temp_file_path
        ))

        # Store the dump file on the backup bucket.
        with open(temp_file_path, 'rb') as database_backup_file:
            target_file_path = '{timestamp}/{path}'.format(timestamp=self.timestamp, path=file_path)
            backup_storage.save(target_file_path, database_backup_file)
            logger.info('Database dump successfully copied to the target storage backend.')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号