sql server - How to use result output columns as objects in MSSQL -
what i'm trying achieve finding out how long retention database backup has using datediff function. in order use datediff need compare, data result, because don't know being anywhere else.
why result ?
i found out command gives me info need accomplish task (backupfinishdate, expirationdate):
restore headeronly disk = 'x:\backups\backuptest.bak'
i'm pretty sure i'm not allowed create temp tables in production servers, if 1 option, i'm afraid can't use that.
ps! if there's better way find out retentiondays of backup, i'd happily use that. if possible in powershell, better.
well, seemed answered own question powershell hint.. gave myself :p
solution was:
$bkp_start = invoke-sqlcmd -serverinstance myserver -query "restore headeronly disk = 'x:\backups\backuptest.bak'" | select-object -expandproperty backupfinishdate $bkp_end = invoke-sqlcmd -serverinstance myserver -query "restore headeronly disk = 'x:\backups\backuptest.bak'" | select-object -expandproperty expirationdate $retentionindays = new-timespan -start $bkp_start -end $bkp_end | select-object -expandproperty days write-output "retention period : $retentionindays"
i love powershell.. looks bit clunky, works , don't know better way @ time.
Comments
Post a Comment