Add script and command for creating backups
This commit is contained in:
parent
3f37dd8940
commit
8c630ada1f
|
@ -0,0 +1,15 @@
|
|||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.core.cache import cache
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Record where the last backup was saved.'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('backup_path', type=str)
|
||||
|
||||
|
||||
def handle(self, *args, **options):
|
||||
backup_path = options['backup_path']
|
||||
cache.set('backup_path', backup_path)
|
||||
self.stdout.write('Set backup path to: ' + backup_path)
|
||||
|
30
apiserver/create_backup.sh
Executable file
30
apiserver/create_backup.sh
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
|
||||
# be safe
|
||||
set -euf -o pipefail
|
||||
|
||||
|
||||
uuid="`cat /proc/sys/kernel/random/uuid`"
|
||||
date="`date -I`"
|
||||
|
||||
api_folder="/opt/spaceport/apiserver"
|
||||
data_folder="/opt/spaceport/apiserver/data"
|
||||
backup_folder="/opt/spaceport/apiserver/backups"
|
||||
|
||||
file_name="spaceport-backup-${date}.tar.gz"
|
||||
path_name="${backup_folder}/${uuid}"
|
||||
full_name="${path_name}/${file_name}"
|
||||
|
||||
mkdir "${path_name}"
|
||||
tar -czf "${full_name}" --directory "${api_folder}" data/
|
||||
|
||||
echo "Wrote backup to: ${uuid}/${file_name}"
|
||||
|
||||
/opt/spaceport/apiserver/env/bin/python \
|
||||
/opt/spaceport/apiserver/manage.py \
|
||||
set_backup_path "${uuid}/${file_name}"
|
||||
|
||||
# test these carefully
|
||||
find "${backup_folder}" -mindepth 1 -type d -print
|
||||
#find "${backup_folder}" -mindepth 1 -type d -ctime +14 -print
|
||||
#find "${backup_folder}" -mindepth 1 -type d -ctime +14 -exec rm -r {} \;
|
Loading…
Reference in New Issue
Block a user