Retention policy configuration
To apply the retention policy to our backups, we need to add some configurations on the PSH backup server. As you can see above in the Backup configuration, the backups are sent to a server and this server stores the backups of all the applications and databases used for VMMC and eLearning.
The backup server has Windows OS, so this configuration applies to Windows.
The folder to store all the backups is this one:
D:\SFTPRoot\backups
In 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 name of this file 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 just need to run it every day. To do this, the server uses the Windows tool schtasks. To set the appropriate configuration, in the shell you just need to run 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
Remember, contact with the admin to set the <user-windows> and the <user-pwd>