BACKUP AND RESTORE sintax
BACKUP DATABASE [dbname] TO DISK = N'D:\Database\Backup\20180102_dbname.bak' WITH COPY_ONLY, NOFORMAT, INIT, NAME = N'dbname-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
declare @backupSetId as int
select @backupSetId = position from msdb..backupset where database_name=N'dbname' and backup_set_id=(select max(backup_set_id) from msdb..backupset where database_name=N'dbname' )
if @backupSetId is null begin raiserror(N'Verify failed. Backup information for database ''dbname'' not found.', 16, 1) end
RESTORE VERIFYONLY FROM DISK = N'D:\Database\Backup\20180102_dbname.bak' WITH FILE = @backupSetId, NOUNLOAD, NOREWIND
GO
RESTORE DATABASE [dbname] FROM DISK = N'D:\MSSQLSERVER\20180102\20180102_dbname.bak' WITH FILE = 1,
MOVE N'dbname' TO N'D:\Database\DATA\dbname.mdf',
MOVE N'dbname_log' TO N'D:\Database\DATA\dbname.LDF', NOUNLOAD, REPLACE, STATS = 10
GO