Delete old backup files

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 16 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
bruskie
Posts: 7
Last visit: Mon Jun 18, 2007 12:40 am

Delete old backup files

Post by bruskie »

Hi there,

I run the following script in a scheduled task to make basic copies (backups) of files and folders, compress these using 7zip and move them to another location. Very basic backup, but it works.

Would someone know how I could add that files older then x are deleted to save space on the remote location? I would like to keep 7 days worth of copies and anything older is to be deleted.

Current script is below:

::set date and time stamp
set DateStamp=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%set TimeStamp=%TIME::=%set TimeStamp=%DateStamp%%TimeStamp:.=%set TimeStamp=%TimeStamp: =0%

:: create the .7z file
7z a -t7z backup%timestamp% c:Files -ms -mmt3 -mx1

:: move/copy the .7z file to another location (eg. network drive)
xcopy backup%timestamp%.7z z:

:: delete the .7z backup file from local machine (temp file)
del %timestamp%.7z

Would really appreciate any assistance
bruskie
User avatar
bruskie
Posts: 7
Last visit: Mon Jun 18, 2007 12:40 am

Delete old backup files

Post by bruskie »

Hi there,

I run the following script in a scheduled task to make basic copies (backups) of files and folders, compress these using 7zip and move them to another location. Very basic backup, but it works.

Would someone know how I could add that files older then x are deleted to save space on the remote location? I would like to keep 7 days worth of copies and anything older is to be deleted.

Current script is below:

::set date and time stamp
set DateStamp=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%set TimeStamp=%TIME::=%set TimeStamp=%DateStamp%%TimeStamp:.=%set TimeStamp=%TimeStamp: =0%

:: create the .7z file
7z a -t7z backup%timestamp% c:Files -ms -mmt3 -mx1

:: move/copy the .7z file to another location (eg. network drive)
xcopy backup%timestamp%.7z z:

:: delete the .7z backup file from local machine (temp file)
del %timestamp%.7z

Would really appreciate any assistance
bruskie
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

Delete old backup files

Post by jhicks »

One quick and dirty solution would be to use Robocopy to copy files older than 7 days to a temp directory and then wack the temp directory and all the files.mkdir c:disposalrobocopy c:files c:disposal /mov /minage:7 rmdir c:disposal /q /sThis is also an opportunity, since you need new functionality, to move this operation to PowerShell. You wouldn't need to muck around trying to parse out dates and times. The whole process would be much simpler and easier.
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

Delete old backup files

Post by jhicks »

That looks like a great utility to get the job done. I've not used this tool, but at a glance your syntax looks ok. Non-production testing will tell your for sure.
This topic is 16 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked