From Basic to Something More SQL Backup 102 From Basic to Something More
Thanks You
How I am I work for Virginia state as SQL DBA I work 18+ year for IT and with SQL since SQL 7 I love computer, database and some computer game
Agenda Database Mission. Backup Plan. Backup Parameters. Other database technique for backup.
Mission of Database Store the data Return stored data Protect data INSERT, UPDATE and DELETE Return stored data SELECT High Availability Protect data BACKUP / RESTORE, Disaster Recovery Security: user, permission, encryption, SSL Performance Index, Index View, Statistic
Backup Type Full Backup Differential Backup Transaction Log Backup Captures current state of the data at the time when backup is finished. Differential Backup Captures only the final state of data that has been changed since the last full backup. Transaction Log Backup Captures every change of the data that has been changed since last log backup. Tail Log Backup Similar to transaction log but perform on broken server from last transaction log to break time if possible with nonrecovery or continue_after_error option.
Sample Backup Plan Full Backup: every Sunday 8 PM. Differential Backup: everyday at 8 PM except Sunday. Transaction Log Backup: everyday from 8 AM to 6 PM for each 2 hours.
Sample Backup Plan - Recovery Failure on Wed at 1pm. Restore Full from Sun. Restore Differential from Tue. Restore Transaction Log from Wed (8am, 10am, 12pm). Restore Tail Log from 12pm to 1pm. With norecovery/no_truncate or continue_after_error
Backup Syntax BACKUP { DATABASE | LOG} <database_name> TO <backup_device> [, <bd>] WITH differential copy_only, mirror to { compression | no_compression} description = ‘text’ | name = <backup_set_name> stats [ = %] buffercount = <val>, maxtransfersize = <val>, blocksize= <val> expire_date=<date>, retaildate=<days> { noinit | init }, { noskip | skip }, { noformat | format } encryption algorithm = {AES_128|AES_192|AES_256|TRIPLE_DES_3KEY} , <encryptor_options>) { noinit | init } append | overwrite { noskip | skip } check expiration date noformat = preserves existing media header and backup sets
Restore Syntax RESTORE [DATABASE | LOG ] <database_name> FROM <backup_device> [, <bd>] WITH { recovery | norecovery | standyby = <standby_file_name>} move <logical_filename> to <physical_filename> log only: { stopat = <datetime> | {stopmark | stopmark} = <lsn:lsn#|after <datetime> > } buffercount = <val>, maxtransfersize = <val> restart file = <file_id> Device can be DISK, TAPE, URL
Other Usable Command Schrödinger Cat Schrödinger Backup RESTORE FILELISTONLY FROM <backup_device> RESTORE HEADERONLY FROM <backup_device> RESTORE VERIFYONLY FROM <backup_device> VERIFYONLY can lead to false positive (good backup), it only check the backup file is readable, it does not attempt to verify the structure of the data in the backup file. VERIFYONLY does not attempt to verify the structure of the data in the backup file. Schrödinger Backup The condition of any backup is unknown until a restore is attempt.
Demos Backup / Restore from TSQL/ssms Backup from SQL Maintenance Plans
Other Techniques Attach / detack database Import / Export sp_detach_database [ @dbname= <dbname> ] Sp_attach_database [ @dbname= <dbname> ], [ @filename = <fname> ] Import / Export ssms: db task Import / Export Data Dacpac: backup database structure and data (?) It is a aip file with extensile dacpac than contain xml files. ssms: db tasks Extract Data-tier application. Command line, powershell, Visual Studio and Red Gate SQL Compare.
More Techniques Log Shipping Process that synchronize transaction log backup and its restore to a secondary database. Replication Process that replicate data at table level. Types: transactional, snapshot and merge (bidirectional)
Demos 2 Attach / Detach. Import / Export. Create dacpac file and see the content. Log Shipping.