sqlschool.gr logo

articles

Articles of SQLschool.gr Team

SQL Server Express – Schedule backup

Antonios Chatzipavlis
Sunday 13 September 2009

Μόλις έλαβα ένα request από τον συνάδελφο Γιώργο Σίμο να φτιάξω κάτι για να παίρνει schedule backup στο sql server express, μιας και αυτή η έκδοση δεν έχει τον sql server agent.

Λοιπόν όποιος θέλει να υλοποιήσει μια τέτοια λύση θα πρέπει να κάνει τα εξής βήματα:

BHMA 1o

Αποθηκεύω το παρακατώ script σε ένα αρχείο πχ c:\My SQL Scripts\DBBackupPerDay.sql

declare @weekday char(3)
declare @command varchar(2048)
select @weekday=upper(left(datename(dw,getdate()),3))
set @command = 'backup database $(dbname) to disk =''$(backupPath)\$(dbname)_'+@weekday+'.bak' + ''' with init'
exec (@command)

Εδώ έχω πάρει σαν υπόθεση εργασίας ότι κάθε μέρα θα παίρνουμε ημερήσιο full backup την βάση μας σε ξεχωριστό device, το οποίο στην επόμενη φορά που θα ξαναπάρω backup σε αυτό θα σβήνει το προηγούμενο. Δηλαδή έστω ότι είναι Δευτέρα και παίρνω backup την επόμενη Δευτέρα θα σβηστεί το backup αυτής. Εάν υπάρχει ανάγκη για κάτι διαφορετικό ενημερώστε με να σας δώσω την λύση.

ΒΗΜΑ 2ο

Ανοίγουμε τον Windows Task Scheduler και φτιάχνουμε ένα νέο Task (Create Task).

image

Δίνουμε όνομα και βάζουμε να τρέχει το συγκεκριμένο με ένα windows account που έχει πρόσβαση στον sql server σαν administrator ( η εύκολη λύση ) ή σαν απλός χρήστης αλλά που το έχουμε δώσει να παίρνει backup databases. Επίσης θα πρέπει να έχει write permissions στο directory στο οποίο πρόκειται να τοποθετήσουμε τα backup μας.

ΒΗΜΑ 3ο

Πάμε στο Action Tab και φτίαχνουμε ένα νέο action στο οποίο βάζουμε τα εξής

image

στο (1) βάζουμε το SQLCMD.exe μαζί με το full path του λογικά θα είναι το 

"C:\Program Files\Microsoft SQL Server\90\Tools\binn\SQLCMD.EXE"

στο (2) βάζουμε τα εξής

/S .\sqlexpress /E /i "c:\My SQL Scripts\DBBackupPerDay.sql" -v dbname=MyDB backuppath=”c:\backups"

στις dbname, backuppath βάζουμε αντίστοιχα το όνομα της βάσης μας και το directory στο οποίο θέλουμε να αποθηκεύονται αυτά.

ΒΗΜΑ 4ο

Τέλος φτιάχνουμε έναν Trigger ( Trigger Tab ) για να πούμε κάθε πότε θέλουμε να γίνεται η εκτέλεση τoυ backup.

Καλά backup!!!

Antonios Chatzipavlis

Antonios Chatzipavlis

Antonios is a Data Solutions Consultant and Trainer. He has been working in IT since 1988. In his career, he has worked as senior developer, IT Manager, Solutions Architect and IT Consultant. Since 1995 he has been devoted on new technologies and software development tools, mainly by Microsoft, either by training company staff and colleagues or assisting them in design, development and implementation as a consultant or chief developer. He has focused in Databases and Data Science since 1995. He specialized in Microsoft SQL Server since version 6.0 in areas like SQL Server Internals, Database Design and Development, Business Intelligence and in 2010 he has started working with Azure Data Platform, NoSQL databases, Big Data Technologies and Machine Learning. He is an active member of many IT communities in Greece, answering colleagues' questions and writing articles in his web site. He is the owner of SQLschool.gr which is a community portal with a lot of information about Microsoft SQL Server. He has been a Microsoft Certified Trainer (MCT) since 2000. Microsoft honored him as MVP on Data Platform due to his activities in SQL Server since 2010. He holds a large number of Microsoft Certifications and Microsoft SQL Server Certifications since version 6.5.

Episode

Transparent Data Encryption (TDE)

image

More Episodes...

Tip

Refresh Intellisence in SSMS

Για να κάνουμε refresh το intellisence μέσα στο SSMS αρκεί να πατήσουμε Ctrl+Shift+R

More Tips...

Become a member

If you want to receive updates from us become a member to our community.

Connect

Explore

Learn


sqlschool.gr © 2010-2023 All rights reserved

This site uses cookies for operational and analytics purposes only. By continuing to browse this site, you agree to their use.