locked
Rename Backup with date and time RRS feed

  • Question

  • Hi guys 

    I want to make daily backup,  I want to rename as : 

    "dbOperacional-25/08/2017-11:41.bak",  But it doesn't work.

    After make the backup, it is:

    SUPORTE03-MSSQL12.SQLEXPRESS-dbOperacional-131481460260556509.bak

    My script is:

    Get-ChildItem "d:\teste\*.bak" | ForEach-Object {
    Rename-Item $_.FullName "$BackupFolder$($_.BaseName -replace "SUPORTE03-MSSQL12.SQLEXPRESS-", """)$(-replace (Get-Date -Format "dd-MM-yyyy") |Where { $_.Name -like "d*" -and "*.bak"}.bak"}

    I still did not insert the time.

    There is someone to help me ?

      

    Friday, August 25, 2017 2:45 PM

Answers

  • $datestring = Get-Date -Format dd-MM-yyyy
    Get-ChildItem d:\teste\*.bak | 
    	ForEach-Object {
    		$newname = $_.BaseName -replace 'SUPORTE03-MSSQL12.SQLEXPRESS-', $datestring
    		$_ | Rename-Item -NewName $newname
    	}
    If there is more than one file then you will have to account for that and provide some kind of name changes.

    \_(ツ)_/

    • Marked as answer by Santos J Friday, August 25, 2017 7:08 PM
    Friday, August 25, 2017 4:07 PM