Skip to content

Instantly share code, notes, and snippets.

@opencoca
Created March 31, 2017 23:26
Show Gist options
  • Save opencoca/fde12f02028daa04a44181e498eae191 to your computer and use it in GitHub Desktop.
Save opencoca/fde12f02028daa04a44181e498eae191 to your computer and use it in GitHub Desktop.
A simple little script that exports django filer files.
import os
import filer
from shutil import copyfile
def ensure_dir(file_path):
if not os.path.exists(file_path):
os.makedirs(file_path)
backup_dir = "/backup_dir"
ensure_dir(backup_dir)
folders = filer.models.Folder.objects.all()
for folder in folders:
print backup_dir + "/" + folder.name
ensure_dir(backup_dir + "/" + folder.name)
files = folder.files.all()
for file in files:
#print file.path
file.name = os.path.split(file.path)[1]
print " " + file.name
copyfile(file.path, backup_dir + "/" + folder.name + "/" + file.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment