Skip to content

Python script to automatically backup Django databases and delete old ones past a certain date on PythonAnywhere's scheduled tasks.

License

Notifications You must be signed in to change notification settings

samsuchin/PythonAnywhere-Database-Backups

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

PythonAnywhere-Database-Backups

Customizable Python script to simultaneously backup Django databases and delete old ones after a certain time frame on PythonAnywhere's scheduled tasks. This script uses Django's dumpdata and excludes contenttypes and auth.permission. I found dumpdata to be friendlier than mysqldump. After dumpdata, one can simply loaddata to fill in the database. https://docs.djangoproject.com/en/3.0/ref/django-admin/

Why should I use this?

The importance of backing up your website database is given. This script allows one to not only save daily backups of their Django site but to also automatically delete old backups to save storage. I use this script for all my websites and wish I had it when I started web dev.

How to use

Save this file as backup.py in your Django Root folder where manage.py is located on PythonAnywhere.

Create a backup folder in your Django Root to store the backups. fixtures/ is commonly used.

Open the backup.py file, and then edit the top variables to work with your website. Also, change the python version at the very top of the file to match yours.

Then navigate to Tasks on PythonAnywhere. Enter...

source virtualenvwrapper.sh && workon (YOUR VENV NAME) && (YOUR PYTHON VERSION) /home/(PYTHONANYWHERE USERNAME)/(DJANGO_ROOT_FOLDER)/backup.py

With this template, yours could look like...

source virtualenvwrapper.sh && workon venv && python3.8 /home/samsuchin/mysite/backup.py

Enter the frequency and time to run the script, and then finally create it.

About

Python script to automatically backup Django databases and delete old ones past a certain date on PythonAnywhere's scheduled tasks.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages