Skip to content

Instantly share code, notes, and snippets.

@juanonsoftware
Last active April 12, 2018 10:00
Show Gist options
  • Save juanonsoftware/de04743be3e008d82dd61710d026af0d to your computer and use it in GitHub Desktop.
Save juanonsoftware/de04743be3e008d82dd61710d026af0d to your computer and use it in GitHub Desktop.
Script to get all backup of a SQL Server database
declare @dbName varchar(255);
set @dbName = 'TestDB';
SELECT m.physical_device_name,
b.backup_start_date,
b.backup_finish_date,
b.type,
b.backup_size/1024/1024 AS BackupSizeMB,
b.compressed_backup_size/1024/1024 as CompressedBackupSizeMB
FROM msdb.dbo.backupset b
JOIN msdb.dbo.backupmediafamily m ON b.media_set_id = m.media_set_id
WHERE b.database_name = @dbName
ORDER BY backup_finish_date DESC
@juanonsoftware
Copy link
Author

To check if a file is existing by sql:

DECLARE @Result INT
EXEC master.dbo.xp_fileexist 'D:\Wip\Practices\OpenSource\FolderListioning\FolderToWatch\Config.txt', @Result OUTPUT
print @Result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment