-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompts.txt
More file actions
101 lines (60 loc) · 3.96 KB
/
Copy pathprompts.txt
File metadata and controls
101 lines (60 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
Creiamo un sistema di backup per server linux.
Crea un agente in un singolo file python 3.x che risiede sul server e che esegue i comandi necessari in locale.
I dati del server saranno presenti in un file yaml che verrà posizionato nel server al momento del setup del file dell'agente.
Le informazioni del file yaml (del quale ti chiedo di crearne un esempio) sono le seguenti:
DB
db_type: "mysql/mariadb"
db_host: "127.0.0.1"
FILES
files_dir_path: "/var/www/something/current"
L'agente deve fare il backup di 2 cose:
1. Il dump del server SQL che sarà mysql o mariadb tramite mysql_dump (o simile) e che poi comprimerà in un file tar.gz chiamato "[YYYY-MM-DD.hh:mm]_[server_name]_db.tar.gz";
2. Il backup della root directory del webserver che comprimerà in un file tar.gz chiamato "[YYYY-MM-DD.hh:mm]_[server_name]_root_files.tar.gz"
Una volta fatti i due step precedenti, l'agente deve creare un nuovo file tar.gz con all'interno i due file di cui sopra, chiamandolo "[YYYY-MM-DD.hh:mm]_[server_name]_root_files_and_db.tar.gz"
Come prima cosa l'agente deve verificare la correttezza del file di configurazione yaml. Se il formato non è corretto o se non lo trova l'esecuzione deve interrompersi.
---
add in the yaml file a new section called "SYSTEM":
SYSTEM
server_name: foobar.com
And change occurrencies in the code to use it as value for filenames
---
add in the yaml file at the end some new sections:
BACKUP
destination_type: "ftp, sftp"
that describe where the final backup should be sent.
Per each destonation_type, add a new section in the yaml file with the configuration parameters needed to make it work
after that, implement in the code the functions needed to implement the destination
---
add in BACKUP section a new parameter to set how many backups must be preserved (older ones must be selected and deleted automatically).
after the add, implement the code accordingly
---
modifica lo script affinché, al posto o per completare i dati del config.yaml possa utilizzare delle variabili di environment settate prima della sua esecuzione.
Se un dato è presente nel config.yaml e nella relativa variabile di ambiente, ha la precedenza la variabile di ambiente.
Modifica lo script perché la presenza del file config.yaml non sia più obbligatoria (ma in questo caso devono esserci le variabili di ambiente necessarie).
Documenta nel file readme questa possibilità e inserisci i relativi test
---
insert in the config.yaml (or by environmental variables) to execute:
- a command before the beginning of backup operations
- a command after all the backup operations but before the transfer to the final destination
- a command after all the operations, included the transfer to the final destination
---
insert, as example of after all operations in the readme file, an "rclone sync" command
---
Change the backup log name adding "[YYYY-MM-DD.HH:MM]" prefix. Add a new section in config.yaml called LOGS in which you can define how many backup logs should be preserved before rotating. The rotation follows the same logic as "keep_backups" in the BACKUP section. After changing the script, update tests and the readme file.
---
rename the script from main.py to backitup.py and update all the occurrencies everywhere (comments, readme, etc)
---
add seconds in filename timestamps, put all the logs in a directory (create it if it doesn't exist) and add, under LOGS (in config), a directive for specify the path of the log directory
---
three problems:
- if I change "log_dir" in "backup_logs" I still see the creation of "logs" directory. There must be an error.
- i see a log file with this name '[2025-05-28.20:08:02]_backup.log' it should not have ' character nor [ and ]
- the log file I see it's empty
Solve them
---
change the format of the timestamp in file names from 2025-05-28.20:06:13_sp.twig.design_root_files_and_db.tar.gz to 20250528_200613_sp.twig.design_root_files_and_db.tar.gz
---
TODO
-
FOR THE FUTURE
replace all the code for sftp with a single command of bash