Principale utente con più risposte
Backup con cancellazione dei backup scaduti

Domanda
-
Buongiorno a tutti,
vorrei creare un set di backup settimanale con la cancellazione dei set di backup scaduti.
E' possibile farlo?
ho creato questo comando da eseguire con un istruzione batch ma mi sembra di non esserci riuscito:
BACKUP DATABASE[NomeDataBase] TO DISK=N'Z:\Backup\NomeDataBase.bak'WITH RETAINDAYS=7,NOFORMAT,NOINIT, MEDIANAME=N'NomeDataBase.bak', NAME=N'NomeDataBase_Backup_Completo',SKIP,NOREWIND,NOUNLOAD, CHECKSUM
In sostanza vorrei eseguire un backup tutti i giorni cancellando in automatico il backup del giorno della settimana precedente che è scaduto.
Dove posso trovare informazioni in merito o chi mi può aiutare?
Grazie a tutti
Marco Dell'Oca
Risposte
-
Nel seguente link trovi la spiegazione dell'arcano problema
https://blog.sqlauthority.com/2017/10/12/sql-server-retaindays-not-delete-backup-x-days/
If you want to delete your backup files which were created earlier, you may want to go with the route of sqlcmd or powershell.
The option RETAINDAYS achieves a very different purpose with Backup. It just prevents users to overwrite the backup file if the user is trying to do it with INIT option. Otherwise, it really does not do anything else. If the user is using the FORMAT option, the backup will be overwritten anyway. This means the use of RETAINDAYS is very much limited.
Caio Gastone
Gastone Canali >http://www.armadillo.it
Se alcuni post rispondono al tuo quesito(non necessariamente i miei), ricorda di contrassegnarli come risposta e non dimenticare di contrassegnare anche i post utili. GRAZIE! Ricorda di dare un occhio ai link Click Here andHere- Contrassegnato come risposta Marco Dell'Oca giovedì 14 marzo 2019 16:59
-
Ciao Per fare questo potresti sostituire il nome files con la data , e fare un datediff per il job di cancellazione .
SET @datafile = ( select getdate())
SET @nomefile = @path + @nome + '_' + @dafafile + '.bak'
BACKUP eccetera eccetera TO DISK = @nomefile
Qualcosa tipo questo.
Saluti
QuirinoS
- Contrassegnato come risposta Marco Dell'Oca giovedì 14 marzo 2019 16:59
Tutte le risposte
-
Nel seguente link trovi la spiegazione dell'arcano problema
https://blog.sqlauthority.com/2017/10/12/sql-server-retaindays-not-delete-backup-x-days/
If you want to delete your backup files which were created earlier, you may want to go with the route of sqlcmd or powershell.
The option RETAINDAYS achieves a very different purpose with Backup. It just prevents users to overwrite the backup file if the user is trying to do it with INIT option. Otherwise, it really does not do anything else. If the user is using the FORMAT option, the backup will be overwritten anyway. This means the use of RETAINDAYS is very much limited.
Caio Gastone
Gastone Canali >http://www.armadillo.it
Se alcuni post rispondono al tuo quesito(non necessariamente i miei), ricorda di contrassegnarli come risposta e non dimenticare di contrassegnare anche i post utili. GRAZIE! Ricorda di dare un occhio ai link Click Here andHere- Contrassegnato come risposta Marco Dell'Oca giovedì 14 marzo 2019 16:59
-
Ciao Per fare questo potresti sostituire il nome files con la data , e fare un datediff per il job di cancellazione .
SET @datafile = ( select getdate())
SET @nomefile = @path + @nome + '_' + @dafafile + '.bak'
BACKUP eccetera eccetera TO DISK = @nomefile
Qualcosa tipo questo.
Saluti
QuirinoS
- Contrassegnato come risposta Marco Dell'Oca giovedì 14 marzo 2019 16:59
-
-
Grazie Quirino,
ho risolto in questo modo:
DECLARE @DATA datetime DECLARE @giorno varchar(3) DECLARE @nomefile varchar(100) DECLARE @nomemedia varchar(100) DECLARE @nomedatabase varchar(100) DECLARE @ampm varchar(2) SET @ampm = CASE WHEN DATEPART(HOUR, GETDATE()) BETWEEN 0 AND 11 THEN 'AM' ELSE 'PM' END SET @DATA = GETDATE() set @giorno = CASE (DATEPART(dw, @DATA) + @@DATEFIRST) % 7 WHEN 1 THEN 'Dom' WHEN 2 THEN 'Lun' WHEN 3 THEN 'Mar' WHEN 4 THEN 'Mer' WHEN 5 THEN 'Gio' WHEN 6 THEN 'Ven' WHEN 0 THEN 'Sab' END SET @nomedatabase = N'dbname' SET @nomemedia = @nomedatabase + '_' + @giorno + '_' + @ampm + '.bak' SET @nomefile = N'z:\Backup\' + @nomemedia BACKUP DATABASE @nomedatabase TO DISK = @nomefile WITH FORMAT, INIT, MEDIANAME = @nomemedia, NAME = N'DbName-Backup Completo', SKIP, NOREWIND, NOUNLOAD, CHECKSUM GO
Marco Dell'Oca
- Modificato Marco Dell'Oca domenica 17 marzo 2019 13:56 errore