To apply the retention policy to our backups, we have to add some configurations on the backup server storage.
As you see previously on the Backup configuration, the backups are sent to a server and it storages the backups of all the applications and databases used for VMMC and eLearning.
The backup server has Windows OS, so this configuration applies to this SO.
The folder to store all the backups is this:
D:\SFTPRoot\backups
Into this folder, you will see different folder for each proposal (vmmc, moodle, monitoring…).
Here we have the script to apply the retention policy configuration. the file’s name is cleanBackup.bat
the content of this file is:
ECHO [%DATE% %TIME%] --------------------------------------------------- ECHO [%DATE% %TIME%] Removing old backups. Please wait... ECHO [%DATE% %TIME%] --------------------------------------------------- ECHO Removing daily backups after 31 days... forfiles /P d:\SFTPRoot\backups\ /S /M *_d-MOH-ZWE*.* /D -31 /C "cmd /c dir @path" forfiles /P d:\SFTPRoot\backups\ /S /M *_d-MOH-ZWE*.* /D -31 /C "cmd /c del @path" ECHO [%DATE% %TIME%] done. ECHO [%DATE% %TIME%] --------------------------------------------------- ECHO [%DATE% %TIME%] removing weekly backups after 6 months(180 days)... forfiles /P d:\SFTPRoot\backups\ /S /M *_w-MOH-ZWE*.* /D -180 /C "cmd /c dir @path" forfiles /P d:\SFTPRoot\backups\ /S /M *_w-MOH-ZWE*.* /D -180 /C "cmd /c del @path" ECHO [%DATE% %TIME%] done. ECHO [%DATE% %TIME%] --------------------------------------------------- ECHO [%DATE% %TIME%] removing weekly backups after 7 years(2556 days)... forfiles /P d:\SFTPRoot\backups\ /S /M *_m-MOH-ZWE*.* /D -2556 /C "cmd /c dir @path" forfiles /P d:\SFTPRoot\backups\ /S /M *_m-MOH-ZWE*.* /D -2556 /C "cmd /c del @path"
Having this configuartion file, we only need execute it every day. To do that, the server uses the schtasks windows tool. To set the proper configuration, on the shell just execute this line:
schtasks /create /RU "<windows-user>" /RP "<windows-pwd>" /SC DAILY /TN "cleanMoHDailyBackups" /TR "D:\SFTPRoot\backups\cleanBackup.bat > D:\SFTPRoot\backups\deleted_files_log.txt 2>&1" /ST 22:00