Database Backup Declare @name VARCHAR(50)-----database name Declare@path VARCHAR(256)----path for backup files Declare@fileName VARCHAR(256)----filename for backup Declare@fileDate VARCHAR(20)-----used for filename //specify database backup directory SET @path = 'C:\Backup\.csv.gz' //specify filename format SELECT @fileDate = CONVERT (VARCHAR(20), GETDATE(), 112) DECLARE db_cursor CURSOR FOR SELECT name FROM master.dbo.sysdatabases WHERE name NOT IN ('master', 'model', 'msdb', 'tempdb')----exclude these database OPEN db_cursor FETCH NEXT FROM db_cursor INTO @name WHILE @@FETCH_STATUS=0 BEGIN SET @filename= @path + @name + '_' + @fileDate + '.csv.gz' BACKUP DATABASE @name TO DISK = @filename FETCH NEXT FROM db_cursor INTO @name END CLOSE db_cursor DEALLOCATE db_cursor ------------------------------------------------------------------------------------------------------- ENCRYPTION OF THE BACKUP USING YOUR PUBLIC KEY gpg---cert-digest-algo=SHA256--edit-key XXXXXXXXM ------------------------------------------------------------------------------------------------------ Generate a public/private key pair (using GnuPG or anything else gpg--gen-key ----------------------------------------------------------------------------------------------------- crontab line 01 04 1 1 1 /user/bin/some directory/some command 01 04 1 1 1 /user/bin/cron.daily/script.sh ------------------------------------------------------------------------------------------- Setting up Cron Job using crontab Setting Up Cron Job Using crontab: Step 1: Open a Terminal Window (Command Line) in Linux. Step 2: The following is a list of cron directories: • /etc/cron.hourly • /etc/cron.daily • /etc/cron.weekly • /etc/cron.monthly Copy your shell script ‘script.sh` or ‘script’ into one of the directories above. If you need to run the script hourly, place your script file in the “cron.hourly” folder. For daily, place it inside the “cron.daily” and so forth. Step 3: Give the shell script the correct permission. For example, if script is called “script.sh”, set permission a follows: cd /etc/cron.daily/ chmod 755 script.sh Step 4: Add new cron job to crontab: crontab –e This opens vi editor for you. Create the cron command using the following syntax: 1. The number of minutes after the hour (0 to 59) 2. The hour in military time (24 hour) format (0 to 23) 3. The day of the month (1 to 31) 4. The month (1 to 12) 5. The day of the week(0 or 7 is Sun, or use name) 6. The command to run More graphically they would look like this: * * * * * Command to be executed - - - - - | | | | | | | | | +----- Day of week (0-7) | | | +------- Month (1 - 12) | | +--------- Day of month (1 - 31) | +----------- Hour (0 - 23) +------------- Min (0 - 59) An example command would be “0 0 * * * /etc/cron.daily/script.sh”. This would mean that the shell script will exactly execute at midnight every night. To save the changes to the crontab that you just made, hit ESC key, and then type :w followed by :q to exit. To list existing cron jobs: crontab –l To remove an existing cron job: • Enter: crontab –e • Delete the line that contains your cron job • Hit ESC > :w > :q
database-hw9 by OgboJr Productions, LLC | Request PDF. Available from: https://www.researchgate.net/publication/329642361_database-hw9_by_OgboJr_Productions_LLC [accessed Dec 16 2018].

Comments

Popular posts from this blog

MR. AKPARA, O. TV AND FILM PRODUCTIONS, LLC