# Lab 4. Cron jobs. ## *Kseniya Evdokimova* --- ## **Questions to answer:** ### 1. Create backup for any directory with files inside. Create cron job which backups directory at the 5th day of every month. To test later the solution for this question I need to create a directory (`mkdir`) and the files inside of it (`touch`): ![](https://i.imgur.com/81BvfKR.png) For archiving the files we can use either `zip` or `tar` commands. Since `tar` provides the advantage in the compression because of similarities among the files (as it compresses the whole tarball), we will use it. We will create backup by `nano`: ![](https://i.imgur.com/0zz5wlP.png) In the file will be: ![](https://i.imgur.com/XZxDl5y.png) Where - c - create archive - p - preserve permissions - f - specify filename - z (gzip) — zip/unzip the archive with the use of gzip - v - verbose, to print the list of the progress The argument after -cpfzv is where the backup will be saved and under which name. In order to do this I earlier created /backup directory: ![](https://i.imgur.com/WyYdrUu.png) The next argument is what we will backup. I am also adding `echo` for the more clear output. To create cron job which backups directory at the 5th day of every month we will need to wite that in the following format: ![](https://i.imgur.com/7ktLihN.png) Specifically, it will backup every 5th day of the month at 00:00, since * means any. And the same holds for any directory with the files. We can check the correctness of that with `ls` command after the 5th date of the month. Or we can check the result of that script, it should be as the following: ![](https://i.imgur.com/Ub9lCn5.png) ### 2. Install nginx and backup directory with location of index.html. Create cron job which backups directory at midnight every Sunday. Also scipt should delete old or previous backups. To complete this task we need to change the previous backup script with the use of `nano` command: ![](https://i.imgur.com/p7D84FV.png) We are adding `rm` which removes the directory. To remove it with the files recursively, we also use `-r` and `-f` to prevent the error because of empty directory. As in the previous task: For archiving the files we will use`tar`, which provides the advantage in the compression because of similarities among the files (as it compresses the whole tarball). The specifications for the `tar` command: - c - create archive - p - preserve permissions - f - specify filename - z (gzip) — zip/unzip the archive with the use of gzip - v - verbose, to print the list of the progress The argument after -cpfzv is where the backup will be saved and under which name. In order to do this I earlier created /backup directory: ![](https://i.imgur.com/WyYdrUu.png) The next argument is what we will backup. We will use at the beginning of each file 'htmldir' for the easy removing of the backups. I am also adding `echo` for the more clear output. To create cron job which backups directory at at midnight every Sunday we will need to wite that in the following format, since * means any: ![](https://i.imgur.com/J5chEwk.png) Where the order of given values is: ![](https://i.imgur.com/E4iiFQ2.png) And the definitions of values are: ![](https://i.imgur.com/9coxv5X.png) We can check the correctness of that with `ls` command after the Sunday midnight. Or we can check the result of that script, it should be as the following: ![](https://i.imgur.com/iuuPuOr.png)