Created
January 10, 2023 15:45
-
-
Save edrisranjbar/bf9542c68e06d1282042fe838e7e33b7 to your computer and use it in GitHub Desktop.
automatic django backup script - full backup (database and assets)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
printf -v date '%(%Y-%m-%d %H-%M-%S)T' | |
cd backups | |
printf "Creating and opening ${date} directory...\n" | |
mkdir "${date}" | |
cd "${date}" | |
# copy assets directory | |
printf "Copying assets...\n" | |
cp -R ../../static . | |
# generate database backup | |
printf "Getting backup from database...\n" | |
python3.10 ../../manage.py dumpdata --natural-foreign --natural-primary -e contenttypes -e auth.Permission --indent 2 > "$date.json" | |
# make archive file | |
cd .. | |
printf "Creating backup archive file...\n" | |
tar -cf "${date}.tar" "${date}" && rm -rf "${date}" | |
# upload backup archive | |
printf "Uploading backup to remote server...\n" | |
sshpass -p "remote server password" scp "${date}.tar" [email protected]:/home/berbidvps | |
printf "All done :)\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment