ERASEFILES Command not working in script

Trying to get some backups that are going to a local disk to delete after 3 days. Doesn't appear to be working.

Have attempted to use the FILEOPTION command as well but had no luck

Anyone able to help?
SQLBackupC.exe -SQL "BACKUP DATABASES [*] TO
 DISK = 'X:\<TYPE>_<SERVER>_<DATABASE>_<DATETIME yyyymmdd_hhnnss>.sqb'" COMPRESS
ION = 2, ERASEFILES = 3

Comments

  • Hi,

    The command has a syntax error, it misses WITH. Try this
    SQLBackupC.exe -SQL "BACKUP DATABASES [*] TO 
     DISK = 'X:\<TYPE>_<SERVER>_<DATABASE>_<DATETIME yyyymmdd_hhnnss>.sqb'" WITH COMPRESSION = 2, ERASEFILES = 3
    

    and let us know if it still doesn't work.

    Thanks,
    Priya
    Priya Sinha
    Project Manager
    Red Gate Software
  • Hi Priya

    I wasn't getting any syntax errors without the WITH but have added it in just in case.

    I have tried running it again and it still isn't deleting the sqb files older than 3 days, however it is taking backups with compression so that switch is obviously working OK

    Many thanks for your help on this
  • Hi there,
    The reason is because there is a quoting error in the syntax... your script should read:
    SQLBackupC.exe -SQL "BACKUP DATABASES [*] TO
     DISK = 'X:\<TYPE>_<SERVER>_<DATABASE>_<DATETIME yyyymmdd_hhnnss>.sqb' WITH COMPRESSION = 2, ERASEFILES = 3"
    

    Your COMPRESSION=2 and ERASEFILES=3 syntax should be inside the double quotes... because it is not, the SQLBackupC.exe is ignoring the two keywords. The compression will still occur because the default is compression level 1.

    Hope that helps,
    Jason
  • Hi,

    You might be aware but I thought it is worth mentioning that in the last step of the Backup and Restore Wizard, you can view the scripts for 'Command Line' and 'Extended Stored Procedure' under the Script tabs. This might be useful for you.

    Thanks,
    Priya
    Priya Sinha
    Project Manager
    Red Gate Software
  • Jason

    That's exactly what it was, thanks

    Priya

    I didn't know that, I was writing this from scratch. Much handier if you can see the code on the back of the options selected in the GUI.

    This is the way microsoft are going with Powershell in all their new stuff. so you can always see the scripting behind the GUI interface.

    Thanks all
Sign In or Register to comment.