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
Delete old backup files
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.
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.
Delete old backup files
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
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
Delete old backup files
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.
Delete old backup files
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.