When we enable Automated Backup for SQL Server as documented in https://docs.microsoft.com/en-us/azure/azure-sql/virtual-machines/windows/automated-backup and if we setup manual schedule with Weekly backup, we will continue to see the backup of the databases happen daily.
We had few of our customers report this so we wanted to blog about this issue and provide a workaround until the issue is fixed.
There are 2 issues with this, as you see, we do not have an option to select which day of the week you wanted the backup to happen and the other one is with the code issue. This is currently known issue and we are working to fix this in near future, but until then we can work around the issue and fix it by running the following T-SQL to modify and make the changes using Managed Backup commands:
-- Confirm the days_of_week has all the days selected and also get the information about backup_begin_time, backup_duration and log_backup_freq and update accordingly in below scripts SELECT db_name, is_managed_backup_enabled, scheduling_option, full_backup_freq_type, days_of_week, backup_begin_time, backup_duration, log_backup_freq FROM msdb.managed_backup.fn_backup_db_config(NULL) WHERE is_managed_backup_enabled = 1 AND full_backup_freq_type = 'WEEKLY';
NOTE: You see System databases Master, Model and MSDB because I had selected “Backup system database” option in earlier screen shot to enable backups for those aswell.
Things you need to note from about is “backup_begin_time”, “backup_duration” and “log_backup_freq” and parameter we are interested in updating is "@days_of_week".
-- Updating the backup config instance wide so that any new databases created, they already get added with the required info. -- We are updating @days_of_week to required day EXEC msdb.managed_backup.sp_backup_config_schedule @database_name = NULL, @scheduling_option = 'CUSTOM', @full_backup_freq_type = 'WEEKLY', @days_of_week = 'Monday', -- needs updated to your required day @backup_begin_time = '00:00', -- needs updated based on above output @backup_duration = '02:00', -- needs updated based on above output @log_backup_freq = '01:00'; -- needs updated based on above output GO -- Remember for existing databases this will get applied when you manually modify the values for each of them. So we have to manually update for each existing database DECLARE @DBNames TABLE (RowID INT IDENTITY PRIMARY KEY, DBName VARCHAR(500) ); DECLARE @rowid INT; DECLARE @dbname VARCHAR(500); DECLARE @SQL VARCHAR(2000); INSERT INTO @DBNames(DBName) SELECT db_name FROM msdb.managed_backup.fn_backup_db_config(NULL) WHERE is_managed_backup_enabled = 1 AND full_backup_freq_type = 'WEEKLY'; SELECT @rowid = MIN(RowID) FROM @DBNames; WHILE @rowID IS NOT NULL BEGIN SET @dbname = ( SELECT DBName FROM @DBNames WHERE RowID = @rowid ); BEGIN SET @SQL = 'EXEC msdb.managed_backup.sp_backup_config_schedule @database_name = ''' + '' + @dbname + '' + ''' ,@scheduling_option = ''CUSTOM'' ,@full_backup_freq_type = ''WEEKLY'' ,@days_of_week = ''Monday'' -- needs updated to your required day ,@backup_begin_time = ''00:00'' -- needs updated based on above output ,@backup_duration = ''02:00'' -- needs updated based on above output ,@log_backup_freq = ''01:00'''; -- needs updated based on above output EXECUTE (@SQL); END; SELECT @rowid = MIN(RowID) FROM @DBNames WHERE RowID > @rowid; END;
If we now again run the first query above and should see the days_of_week reflect to the day(s) of your choice.
Once done, it should work for any new database created.
Point to note, if you disable and re-enable the Automated backup before the fix is released, we will have to go over the same process again.
Hope this helps!
Dinesh Babu Munugala
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.