Chapter 5 Backups
Create a credentials file (the structure of the file depends on the target cloud server)
Create a
backups.conf
under thebackups
directory usingbackups.conf.example
as base, setting the appropriate value for the several variables.For variables associated with files and directories always use absolute paths.
Variables:
RUN
: Set it to0
if you don’t want the next scheduled backup to run.This variable allows you to cancel any backup runs while you are doing some maintenance on the application.
CONSTANCE_REDIS_DB
: Number of the Redis database where the django constance config is stored. The default value is 2. This value should be the same as the environment variableREDIS_CONSTANCE_DB
of the dashboard container.The following variables are associated with the arguemtns of the
backup_uploader
python package. Check its usage for more details:APP_NAME
: The backup process will generate some directories with this name in places that are shared with other applications.SERVER
: The name of the target cloud server to where backups should be uploaded (dropbox or mega).BACKUP_CHAIN_CONFIG
: Allows having different directories with backups of different ages.CREDENTIALS_FILE_PATH
: File containing the credentials to access the server to upload the backup file.
Install the
backup_uploader
python package by following its install instructions.Schedule your backups
* * * * * Command_to_execute | | | | | | | | | Day of the Week ( 0 - 6 ) ( Sunday = 0 ) | | | | | | | Month ( 1 - 12 ) | | | | | Day of Month ( 1 - 31 ) | | | Hour ( 0 - 23 ) | Min ( 0 - 59 )
(Retrived from: Tutorialspoint)
Ex: To run every day at 3:00 am
crontab -e
Add entry
0 3 * * * $HOME/NetworkDashboards/backups/backup.sh
(The path to the backup script might be different)
Restore
Select the compressed backup you want to restore.
Make sure that all the environment variables are the same as the ones that were used for the chosen backup file. Additionally, the
backups.conf
file is also necessary to set up, since theTMP_DIRECTORY
variable will be used.Run the
backups/restore.sh
script.
Useful stuff
How to create a shared link to a dropbox directory using its python’s API:
pip install dropbox
import dropbox = dropbox.Dropbox(API_TOKEN) d # create a shared link for a directory from dropbox.sharing import SharedLinkSettings = SharedLinkSettings( sharing_settings =True, require_password=DIRECTORY_PASSWORD, link_password ) d.sharing_create_shared_link_with_settings( DIRECTORY_PATH, sharing_settings, ) # get all links for link in d.sharing_get_shared_links().links: print(f"{link.path} -> {link.url}")