{"id":3320,"date":"2015-12-17T05:43:01","date_gmt":"2015-12-17T10:43:01","guid":{"rendered":"https:\/\/academy.sqlbak.com\/?p=3320"},"modified":"2023-10-17T04:52:35","modified_gmt":"2023-10-17T08:52:35","slug":"file-backups","status":"publish","type":"post","link":"https:\/\/academy.sqlbak.com\/file-backups\/","title":{"rendered":"File Backups"},"content":{"rendered":"
SQL Server allows to make backups and restore not only the entire database but also a single filegroup or even a separate file. \u00a0This is called a\u00a0file backup. <\/em>This type of backup\u00a0contains all data from one or more files or filegroups.<\/p>\n File backups are often used to increase the recovery process speed by restoring only damaged files, without restoring the rest of the database, if necessary. Assume there is a database that contains several files. Each file is stored on a separate disk and suddenly one disk fails. In this case the recovery process will not take more time because there is no need to restore the entire database, it will be enough\u00a0to restore\u00a0only the file from the failed disk.<\/p>\n Another use case is when\u00a0some filegroups in your database are updated more frequently than others. In this case you can backup them separately using a file backup.<\/p>\n One of the biggest disadvantages of using file backup is that such backups are difficult to manage. It takes more time to manage every file backup separately. Also,\u00a0if failure\u00a0occurs and the backup of the damaged file is lost the entire database becomes unrecoverable.<\/p>\n Let’s explore how does full file backup work\u00a0under different recovery models.\u00a0Assume there is a\u00a0database “Adventureworks” which contains two filegroups “Group1” and “Group2”, each filegroup includes two files “File1” and “File2” for filegroup “Group1” and “File3” and “File4” for “Group2”.<\/p>\n To make sure that the database can be restored, under the simple recovery model, \u00a0all read-write files<\/em> must be backed up together. It’s quite simple to accomplish this as there is no need to backup all read-write files one by one, you just need to use the READ_WRITE_FILEGROUPS option (known as a partial backup):<\/p>\n <\/p>\n If the database runs under the full recovery model you should backup the transaction log, regardless of the\u00a0file backup strategy you chose. All transaction log backups beginning with the first file backup and a complete set of \u00a0full file backups equal to a full database backup. Please check the picture bellow to understand how it works:<\/p>\n <\/p>\n Note though, that using this backup strategy leads to a complex database restoration process.<\/p>\n If any file is offline then the whole filegroup containing this file is offline too and cannot be backed up.<\/p>\n SQL Server backups only one file at a time. Of course, it is possible to backup multiple files in one operation, but should you need to restore only one file, the restore operation will take\u00a0more time (to find the file, the whole backup will be read).<\/p>\n SQL Server allows to make not only full file or filegroup backups but also a differential file backup. Creating a full file backup makes it possible to apply a differential file backup. If the database runs under the simple recovery model the differential file backup can be applied only to read-only filegroups. As far as the full recovery model is concerned, a differential file backup can be applied to any filegroup which has been previously backed up. Differential file backups reduce time to restore database because less transaction log backups have to be restored. It is better to use differential file backups under the following circumstances:<\/p>\n Making a differential file backup is quite simple, just add “WITH DIFFERENTIAL” option:<\/p>\n <\/p>\n Here is how you can create a file backup using SSMS:<\/p>\n SQL Server allows to make backups and restore not only the entire database but also a single filegroup or even a separate file. \u00a0This is called a\u00a0file backup. This type of backup\u00a0contains all data from one or more files or filegroups. File backups are often used to increase the recovery process speed by restoring only […]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[157],"tags":[],"yoast_head":"\nCase for Simple Recovery Model<\/span><\/a><\/h2>\n
BACKUP DATABASE<\/span>\u00a0Adventureworks\u00a0READ_WRITE_FILEGROUPS, \r\n FILEGROUP = 'Group1', \r\n FILEGROUP = 'Group2' \r\nTO DISK<\/span>\u00a0= 'Groups.bck'<\/span><\/pre>\n
Case for Full Recovery Model<\/h2>\n
BACKUP<\/span> LOG <\/span>Adventureworks TO DISK<\/span> = 'log_13_00.bak'<\/span> \r\nBACKUP DATABASE <\/span>Adventureworks FILEGROUP<\/span> = 'Group2'<\/span> TO DISK<\/span> = 'Group2.bck'<\/span> \r\nBACKUP<\/span> LOG <\/span>Adventureworks TO DISK<\/span> = 'log_14_00.bak'<\/span> \r\nBACKUP DATABASE <\/span>Adventureworks FILEGROUP<\/span> = 'Group1'<\/span> TO DISK<\/span> = 'Group1.bck'\r\n<\/span>BACKUP<\/span> LOG <\/span>Adventureworks TO DISK<\/span> = 'log_15_00.bak'<\/span> \r\nBACKUP DATABASE <\/span>Adventureworks FILEGROUP<\/span> = 'Group3'<\/span> TO DISK<\/span> = 'Group3.bck'<\/span><\/pre>\n
Case for Differential File Backup<\/h2>\n
\n
BACKUP DATABASE <\/span>Adventureworks \r\n FILE<\/span> = '<\/span>File2<\/span>'<\/span>,\r\n FILE<\/span> = 'File3' \r\n<\/span>TO DISK<\/span> = 'Groups_diff.bck'<\/span> WITH DIFFERENTIAL<\/span><\/pre>\n
How to Create\u00a0a File Backup\u00a0with\u00a0SQL Server Management Studio<\/strong><\/h2>\n
\n