Limit Number of Sage Timeslips Database Backup Files
Sage Timeslips offers a Scheduled Backup feature which will help automate the Timeslips database backup process. However, the current Scheduled Backup feature uses the Windows Task Scheduler to execute a Windows batch file which does not include any code limiting the number of backups it creates. I tried contacting Sage support about this but they have no solution at the present moment. Perhaps by the time you are reading this they have one.
In this article I cover what I did to limit the number of Sage Timeslips database backup copies stored within the Backups directory of my client’s computer. Note that I do not work for nor am I in any way affiliated with the Sage company. The information herein is for my personal use only so that I can recall what I did should the need arise. You can hire me to assist you with your Timeslips database backups remotely by contacting me.
If you do not know what you are doing with Windows batch files you may inadvertently and permanently delete important system files or lose vital data. Especially if you fail to properly backup your data and computer. You’ve been warned!
Use the Sage Timeslips Backup Batch File to Limit Backup Files
To limit the number of Sage Timeslips database backups that are stored on the computer I added a single line of code to the default Timeslips backup batch file (Timeslips Backup.bat).
That default batch backup file was generated using the 2021 Sage Timeslips Scheduled Backup feature with the “Append date and time to the filename” checkbox selected.
This checks for any files (not subdirectories) that are older than 8 days. If it finds any, they are permanently deleted. Since my database backs up every day, I will effectively be storing one-weeks worth of Sage Timeslips database backups via this method.
forfiles /p “C:\path\to\dir” /s /m *.* /D -<number of days> /C “cmd /c del @path”
Syntax Code Explanation
- FORFILES – This command allows you to execute a command on each file.
- /p “C:\path2dir” – This is the path to the directory where the files exist that, in my case, I want wish to limit.
- If the path is not specified, it will default to the current folder where the batch file is at (be careful!).
- /s – This flag will ensure the inclusion of any sub-folders.
- /m – This flag matches the specified wildcard, *.* means ALL FILES regardless of file extension. For my purpose I only want to select the Timeslips database backup files which is why I am using the wildcard plus TBU file extension: *.TBU
- /D – This flag specifies a date.
- for files older than 30 days use /D “-30”
- for files new than 30 days use /D “+30”
- You can specify a date using DDMMYY or -DDMMYY
- Example: /D -01/01/2022
- /C – This instructs the command to execute for each file, in this case I specified “cmd /c del @path”
- @path – This is the full path, including name. This is done automatically.
- To bypass the “Are you sure” prompt which will also pause the deletion of any files until you provide confirmation, use: del /F /Q @path
Syntax Code Used
Below is the code that I added to the end of my Timeslips Backup.bat batch file which is called upon every evening via the Windows Task Scheduler.
My backups are located at C:\Timeslips\Backups because I am sharing this folder in my root C: directory with other computers. I only want 30 days (one month) worth of Timeslips database backups so I used -30. I also made sure to only look for .TBU files and I used the /F and /Q flags just before @path to prevent the file deletion confirmation box from appearing. Otherwise, if no one is around to click the OK button on the file deletion confirmation box it won’t delete those old (beyond 30 days) database backup files.
forfiles /p “C:\TimeslipsData\Backups” /m *.TBU /D -30 /C “cmd /c del /F /Q @path”
Syntax Code Variations
Though I did not do this, I could have used and set variables at the top of the batch file. For example, there was a “BACKUPPATH” variable that I could have used so I wouldn’t have to manually set the “forfiles” path. I could have created a “DAYS” variable as well as “FEXT” (file extension) variable to make future changes easier.
CODE NOT TESTED NOR CONFIRMED BELOW! DO NOT USE!!! Simply posted for informational purposes only!
forfiles /p “%BACKUPPATH%” /m %FEXT% /D “%DAYS%” /C “cmd /c del /F /Q @path”
I welcome your thoughts, questions or suggestions on my article on limiting the number of Sage Timeslips database backup copies.
You may support my work by sending me a tip using your Brave browser or by sending me a one time donation using your credit card.
Let me know if you found any errors within my article or if I may further assist you by answering any additional questions you may have.