Skip to content

Instantly share code, notes, and snippets.

@edrisranjbar
Created January 10, 2023 15:45
Show Gist options
  • Save edrisranjbar/bf9542c68e06d1282042fe838e7e33b7 to your computer and use it in GitHub Desktop.
Save edrisranjbar/bf9542c68e06d1282042fe838e7e33b7 to your computer and use it in GitHub Desktop.
automatic django backup script - full backup (database and assets)
#!/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" root@185.231.112.47:/home/berbidvps
printf "All done :)\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment