def create_json_dump():
filepath = os.path.join(settings.DBBACKUP_STORAGE_OPTIONS['location'], 'openkamer-' + str(datetime.date.today()) + '.json')
filepath_compressed = filepath + '.gz'
with open(filepath, 'w') as fileout:
management.call_command(
'dumpdata',
'--all',
'--natural-foreign',
'--exclude', 'auth.permission',
'--exclude', 'contenttypes',
'person',
'parliament',
'government',
'document',
'stats',
'website',
stdout=fileout
)
with open(filepath, 'rb') as f_in:
with gzip.open(filepath_compressed, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
os.remove(filepath)
BackupDaily.remove_old_json_dumps(days_old=30)
评论列表
文章目录