def handle(self, *args, **options):
        backup_name = options['backup_name']
        site_id = options['site_id']

        if not backup_name or not site_id:
            raise Exception('backup_name or site_id is missing')

        # IMPORTANT: if you update this list, please,
        #            see the site_creator.py module too
        models_list = ["magiccontent.Widget",
                       "magiccontent.Area",
                       "magiccontent.SiteLink",
                       "magicgallery.Gallery",
                       "magicgallery.GalleryItem",
                       "textimagecontent.TextImageContent",
                       "formattedtextimagecontent.FormattedTextImageContent",
                       "iconcontent.IconContent",
                       "background.BackgroundArea",
                       "dividertextcontent.DividerTextContent",
                       "imagecontent.ImageContent",
                       "magiccontentnavigation.MenuItem",
                       "core.SitePreferences",
                       "magicthemes.ThemePreferences", ]

        restore = MagicBackup() \
            .from_backup(backup_name) \
            .to_site(site_id)

        for model in models_list:
            print(green('Restoring {0}...'.format(model)))
            restore.model(model).restore()

        print(green('site id {0} populated with backup {1}'.format(
            site_id, restore.original_path)))
    def handle(self, *args, **options):
        backup_name = options['backup_name']
        site_id = options['site_id']

        if not backup_name or not site_id:
            raise Exception('backup_name or site_id is missing')

        models = ["magiccontent.Widget",
                  "magiccontent.Area",
                  "magiccontent.SiteLink",
                  "magicgallery.Gallery",
                  "magicgallery.GalleryItem",
                  "textimagecontent.TextImageContent",
                  "formattedtextimagecontent.FormattedTextImageContent",
                  "iconcontent.IconContent",
                  "background.BackgroundArea",
                  "dividertextcontent.DividerTextContent",
                  "imagecontent.ImageContent",
                  "magiccontentnavigation.MenuItem",
                  "core.SitePreferences",
                  "magicthemes.ThemePreferences", ]

        backup = MagicBackup().site(site_id).save_as(backup_name)
        for model in models:
            print(green('backuping {0}...'.format(model)))
            backup.model(model).backup()

        print(green('new backup created at {0}'.format(backup.target_dir)))
Exemplo n.º 3
0
    def setUp(self):
        # Creating some data
        self._current_site = Site.objects.get_current()
        self._pet_model.objects.create(name="Lucky")
        self._pet_model.objects.create(name="Paçoca")

        # Creating a backup for the given data
        backup = MagicBackup() \
            .site(self._current_site.id) \
            .save_as('mypets-backup')
        backup.model("tests.Pet").backup()

        # Deleting all data
        self._pet_model.objects.all().delete()