Backing Up Django Data in Docker-Compose Environment
Dec. 26, 2022, 1:36 p.m. by Avery Uslaner
I chose to create a simple bash script that runs on a VM on my home network and backups up the database and media files used on this website.
#!/bin/bash
TODAYS_DATE=`date +"%m-%d-%Y"`
ssh -i /home/user/.ssh/data-manager_rsa user@averyuslaner.com 'docker exec user-db mysqldump -u db_user --password=supersecretpassword photo_blog' > /home/user/backups/averyuslaner.com/${TODAYS_DATE}_db_dump.sql
ssh -i /home/user/.ssh/data-manager_rsa user@averyuslaner.com 'docker run --rm -v personal_website_media_volume:/media -v $(pwd)/backups:/backups ubuntu tar cvf /backups/media.tar /media'
scp -i /home/user/.ssh/data-manager_rsa user@averyuslaner.com:/home/user/backups/media.tar /home/user/backups/averyuslaner.com/${TODAYS_DATE}_media.tar
I don't love having the database password in there so I may look for alternatives in the future but I think it is acceptable for now.