https://www.accordbox.com/blog/how-export-restore-wagtail-site/

 

# postgres
python -Xutf8 manage.py dumpdata --natural-foreign --indent 2 \
    -e contenttypes -e auth.permission -e postgres_search.indexentry \
    -e wagtailcore.groupcollectionpermission \
    -e wagtailcore.grouppagepermission -e wagtailimages.rendition \
    -e sessions > data.json
    
# sqlite
python -Xutf8 manage.py dumpdata --natural-foreign --indent 2 -e contenttypes -e auth.permission -e wagtailsearch.indexentry -e wagtailcore.groupcollectionpermission -e wagtailcore.grouppagepermission -e wagtailimages.rendition -e sessions -e wagtailcore.pagerevision > data.json

python -Xutf8 manage.py dumpdata --indent 2 > data.json

 

import os

from django.conf import settings
from django.core.files.storage import default_storage, FileSystemStorage
from django.core.management.base import BaseCommand
from django.core.management import call_command

from wagtail.core.models import Site, Page


class Command(BaseCommand):
    def _copy_files(self, local_storage, path):
        """
        Recursively copy files from local_storage to default_storage. Used
        to automatically bootstrap the media directory (both locally and on
        cloud providers) with the images linked from the initial data (and
        included in MEDIA_ROOT).
        """
        directories, file_names = local_storage.listdir(path)
        for directory in directories:
            self._copy_files(local_storage, path + directory + '/')
        for file_name in file_names:
            with local_storage.open(path + file_name) as file_:
                default_storage.save(path + file_name, file_)

    def handle(self, **options):
        fixtures_dir = os.path.join(settings.PROJECT_DIR, 'fixtures')
        print(os.path.join(fixtures_dir, 'ezstbackend.json'))
        fixture_file = os.path.join(fixtures_dir, 'ezstbackend.json')

        print("Copying media files to configured storage...")
        local_storage = FileSystemStorage(os.path.join(fixtures_dir, 'media'))
        self._copy_files(local_storage, '')  # file storage paths are relative

        # Wagtail creates default Site and Page instances during install, but we already have
        # them in the data load. Remove the auto-generated ones.
        if Site.objects.filter(hostname='localhost').exists():
            Site.objects.get(hostname='localhost').delete()
        if Page.objects.filter(title='Welcome to your new Wagtail site!').exists():
            Page.objects.get(title='Welcome to your new Wagtail site!').delete()

        call_command('loaddata', fixture_file, verbosity=0)

        print("Awesome. Your data is loaded! The bakery's doors are almost ready to open...")

 

python manage.py load_initial_data

python manage.py loaddata data.json

'Back-End > Wagtail, Django 배포' 카테고리의 다른 글

Wagtail Heroku Deploy  (0) 2022.03.01
Wagtail RichText API  (0) 2022.01.07
2. Gunicorn, Nginx 적용  (0) 2021.12.23
1. PostgreSQL 적용  (0) 2021.12.22
3. Docker(Django, Wagtail)  (0) 2021.12.22

+ Recent posts