@ -8,72 +8,20 @@ You will create two scripts that will manage and perform scheduled backups.
The script `backup_manager.py` will orchestrate the backup service and if necessary update the file `backup_schedules.txt`. In order to do so it will accept the following command-line arguments:
The script `backup_manager.py` will orchestrate the backup service and if necessary update the file `backup_schedules.txt`. In order to do so it will accept the following command-line arguments:
- `start`:
- `start`: Runs `backup_service.py` in the background.
- Runs `backup_service.py` in the background.
- `stop`: Kills `backup_service.py` process.
- Checks if the service is already running.
- If the service is already running and you try to run it again it should send an error message to the log file.
- `stop` does the same as start but in order to sop or kill the process `backup_service.py`.
- `create [schedule]`:
- `create [schedule]`:
- Adds a new backup schedule in `backup_schedules.txt`.
- Adds a new backup schedule in `backup_schedules.txt`.
- This schedule will have a specific format which is `"file_name;hour:minutes;backup_file_name"`
- This schedule will have a specific format which is `"file_name;hour:minutes;backup_file_name"`.
- If the schedule format is wrong, an error message should be sent to the log file.
```bash
- `list`: Prints the scheduled backups in `backup_schedules.txt`, adding an index before each schedule.
[08/02/2023 16:07] Backup done for test in backups/backup_test.tar
[dd/mm/yyyy 16:07] Backup done for test in backups/backup_test.tar
[08/02/2023 16:07] Backup done for test1 in backups/personal_data.tar
[dd/mm/yyyy 16:07] Backup done for test1 in backups/personal_data.tar
[08/02/2023 16:07] Backup done for test2 in backups/office_docs.tar
[dd/mm/yyyy 16:07] Backup done for test2 in backups/office_docs.tar
--> Content of ./backups
--> Content of ./backups
backup_test.tar office_docs.tar personal_data.tar
backup_test.tar office_docs.tar personal_data.tar
```
```
### Hints
### Hints
- Familiarize yourself with the Python, including the use of modules such as `subprocess` and `shlex`, and file `I/O` operations.
- Familiarize with Python, including modules such as `subprocess`, `shlex` and file `I/O` operations.
- To run a script from another python script you could use `subprocess.Popen` with the flag `start_new_session=True`.
- To run a script from another Python script you could use `subprocess.Popen` with the flag `start_new_session=True`.
- To kill a process you should find its process id and call `os.kill`.
- To kill a process you should find its process id and call `os.kill`.
- Play with the command `ps -A -f`, it will show a list of all active processes with the arguments attached to them and their process ids.
- Play with the command `ps -A -f`, it will show a list of all active processes with the arguments attached to them and their process ids.
- The standard library `tarfile` is very useful when trying to work with archives.
- The standard library `tarfile` is very useful when trying to work with archives.
- This starts to be quite a big project, try to be as modular as you can by creating single-task functions, this will save you a lot of time.
- This starts to be quite a big project, try to be as modular as possible by creating single-task functions, this will save you a lot of time.
> There is many ways to run tasks in background and to perform actions on a specific time, the implementation proposed in this exercise is good for learning but should not be your preferred choice for production environments.
> There is many ways to run tasks in background and to perform actions on a specific time, the implementation proposed in this exercise is good for learning but should not be your preferred choice for production environments.