Django DBBackup issue

47 Views Asked by At

I want to backup media fileand database of a django project,based on document I install Django-dbbackup, I want to store backup files in dropbox . I ran this command :

pip install dropbox django-storages 

and add following in setting.py

DBBACKUP_STORAGE = 'storages.backends.dropbox.DropBoxStorage'
DBBACKUP_STORAGE_OPTIONS = {
    'oauth2_access_token': 'DROPBOX_TOKEN',
}

now I cant backup ; account of dropbox is base mode and free(2GIG);

token from 'generate access token' button on web site

ERROR:

'D:/default-DESKTOP-RISNQKN-2023-08-13-164717.dump' did not match pattern '(/(.|[\r\n])*|id:.*)|(rev:[0-9a-f]{9,})|(ns:[0-9]+(/.*)?)'
Internal Server Error: /account/admin_ability/
Traceback (most recent call last):
  File "D:\CODES\python\virtualenvs\karapp2\karkpp2\app_account\views.py", line 37, in f_admin_ability
    call_command('dbbackup')
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\django\core\management\__init__.py", line 194, in call_command
    return command.execute(*args, **defaults)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\django\core\management\base.py", line 458, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\dbbackup\utils.py", line 120, in wrapper
    func(*args, **kwargs)
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\dbbackup\management\commands\dbbackup.py", line 93, in handle
    self._save_new_backup(database)
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\dbbackup\management\commands\dbbackup.py", line 120, in _save_new_backup
    self.write_to_storage(outputfile, filename)
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\dbbackup\management\commands\_base.py", line 97, in write_to_storage
    self.storage.write_file(file, path)
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\dbbackup\storage.py", line 86, in write_file
    self.storage.save(name=filename, content=filehandle)
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\django\core\files\storage\base.py", line 37, in save
    name = self.get_available_name(name, max_length=max_length)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\storages\backends\dropbox.py", line 205, in get_available_name
    return super().get_available_name(name, max_length)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\django\core\files\storage\base.py", line 77, in get_available_name
    while self.exists(name) or (max_length and len(name) > max_length):
          ^^^^^^^^^^^^^^^^^
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\storages\backends\dropbox.py", line 126, in exists
    return bool(self.client.files_get_metadata(self._full_path(name)))
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\dropbox\base.py", line 1666, in files_get_metadata
    arg = files.GetMetadataArg(path,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\dropbox\files.py", line 171, in __init__
    self.path = path
    ^^^^^^^^^
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\stone\backends\python_rsrc\stone_base.py", line 81, in __set__
    value = self.validator.validate(value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\stone\backends\python_rsrc\stone_validators.py", line 345, in validate
    raise ValidationError("'%s' did not match pattern '%s'"
stone.backends.python_rsrc.stone_validators.ValidationError: 'D:/default-DESKTOP-RISNQKN-2023-08-13-164717.dump' did not match pattern '(/(.|[\r\n])*|id:.*)|(rev:[0-9a-f]{9,})|(ns:[0-9]+(/.*)?)'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\CODES\python\virtualenvs\karapp2\karkpp2\app_account\views.py", line 44, in f_admin_ability
    return JsonResponse({'state':0,'data':e},status=403)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\django\http\response.py", line 731, in __init__
    data = json.dumps(data, cls=encoder, **json_dumps_params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mohamadreza\AppData\Local\Programs\Python\Python311\Lib\json\__init__.py", line 238, in dumps
    **kw).encode(obj)
          ^^^^^^^^^^^
  File "C:\Users\mohamadreza\AppData\Local\Programs\Python\Python311\Lib\json\encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mohamadreza\AppData\Local\Programs\Python\Python311\Lib\json\encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "D:\CODES\python\virtualenvs\karapp2\.env\Lib\site-packages\django\core\serializers\json.py", line 106, in default
    return super().default(o)
           ^^^^^^^^^^^^^^^^^^
  File "C:\Users\mohamadreza\AppData\Local\Programs\Python\Python311\Lib\json\encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ValidationError is not JSON serializable
[13/Aug/2023 16:47:17] "POST /account/admin_ability/ HTTP/1.1" 500 202467

view:

   if(request.method=='POST'):
        type_command=str(request.POST.get('type'))
        try:
            if(type_command.isdigit()):
                if(type_command=='1'):
                    call_command('dbbackup')
                elif(type_command=='2'):
                    call_command('mediabackup')
                return JsonResponse({'state':1,'data':'backed up successfully'})
        except Exception as e:
            print('===>',e)
            return JsonResponse({'state':0,'data':e},status=403)
0

There are 0 best solutions below