Schedule offline db2 database backup on Windows - database

I only have access to the command line processor and I would like to set up a backup policy to do an offline backup once a day of a db2 database.
Can anyone point me in the right direction?
To do a single offline backup I know the code is
BACKUP DATABASE <database> TO <“drive/location”> <params>
However I can not figure out how to schedule this

If you are using LUW, you can:
In Windows, create a task in the Taks Schedule with the backup command. - http://windows.microsoft.com/en-gb/windows/schedule-task#1TC=windows-7
In linux, put the command in the crontab of a user with the privileges to execute the backup. Remember to load the db2 instance profile.
You can configure automatic backups in any OS - http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.sql.rtn.doc/doc/r0052291.html

If you are using Windows OS, then you create a new task and on the action tab:
Action: Start a program
Program/script: "D:\Program Files\IBM\SQLLIB\BIN\db2cmd.exe" (path there the db2cmd.exe is located)
Add arguments (optional): /c /w /i db2 backup database DBNAME to X:\Backup COMPRESS WITHOUT PROMPTING
Start in (optional): blank
The command above will backup database DBNAME to X:\Backup folder compressing the DB.

Related

Batch file for auto backup

I have a server in which I'm running an SQL Server Express DB and an Azure blob i which I Upload each morning the backup of the SQL Server.
Now, I've been able to automate the backup via a mix of SQL query + batch file and I have it scheduled into my task scheduler to run each night at 9:00pm, but I would like to move also a copy of the backup from the server to the Azure Storage.
I've already tryed a batch file in task scheduler:
echo off
copy "Z:\Backup\SQLBackup\" "C:\Program Files\Microsoft SQL Server\MSSQL14.SQLEXPRESS\MSSQL\Backup\DailyStep_bck.bak"
But it doesn't work by itself, only if I run it manually.
Each day the current copy should replace the older one, I don't need retention of old bacups for now.
I've tryed also robocopy and it also doesn't work... could someone tell me what am I missin?
the task is running as administrator with the "Run wether the admin is loged in or not" option.
thanks for your help.
I summarize the solution as below.
Windows task scheduler doesn't have permissions to the mounted azure file share drive. So we need to use the path https://[Azure_account].file.core.windows.net/storage/Backup to access Azure file share. Besides, if you want to implement auto-upload, you can use azcopy.
For example
Create a sas token for the file share
Script
azcopy copy 'C:\Program Files\Microsoft SQL Server\MSSQL14.SQLEXPRESS\MSSQL\Backup*.bak' 'https://[Azure_account].file.core.windows.net/storage/Backup/SQLBackup/[backup_file].bak?<sas token>
Create a schedule task
For more details, please refer to here and here

SQL Server: Export Databases Locally at Specific Time

We are taking full disk backup of our servers weekly. How do I set up SQL Server 2016 to export all databases automatically to a local folder, every Friday at 6 PM? I'd like to do that to add extra level of protection against database corruption.
I recommend using Ola Hallengren's scripts for database backups. https://ola.hallengren.com/sql-server-backup.html
Remember to DBCC check database before taking a backup and to both validate the backup media and to try your restore scenarios frequently!
Here are the steps from the FAQ:
Download MaintenanceSolution.sql.
In the script, find this line:
SET #BackupDirectory = N'C:\Backup'
and replace C:\Backup with the path to your backup directory.
In the script, find this line:
SET #CleanupTime = NULL
and replace NULL with your cleanup time. The cleanup time is the the number of hours after which the backup files are deleted.
Execute MaintenanceSolution.sql. This script creates all the objects and jobs that you need.
Go into [SQL Server Agent] / [Jobs] and start the jobs that have been created. Verify that these jobs are completing successfully. Verify that the backup files are being created. Check the output files in the error log directory.
Schedule the jobs.

Restore DB2 backup to another DB2 database with different name

I have a DB2 10 database backup file that I would like to restore to another environment. The problem is that the database has been setup with a different name and the restore complains because the database names are different.
Is there a way to restore the database backup file to the other environment?
Thanks
Here is the command I used to restore:
db2 "RESTORE DATABASE <restore database name> FROM <current restore directory> TAKEN AT <timestamp of full backup> TO <Local database directory> INTO <new database name>"
Example:
Database name of original backup is:
SYSTEM
My backup directory is:
/db2inst1/archive/backup/SYSTEM/level0/
Timestamp of original backup is:
20180503141925
Local database directory is: I would redirect this directory to your database standard list
New database name is:
SYSTEM2
Example output command is:
db2 "RESTORE DATABASE system FROM /db2inst1/archive/backup/SYSTEM/level0/ TAKEN AT
20180503141925 TO /db2inst1/ INTO system2"
Once complete roll-forward database:
db2 "ROLLFORWARD DB SYSTEM2 TO END OF LOGS AND COMPLETE"
You can use the "redirected" restore option by generating a file
db2 restore database mydb redirect generate script restore.sql
Once the script is generated, you can change the names, file locations, etc.
And finally, execute the script
db2 -tvf restore.sql
Thanks for the help.
In the end we dropped the existing database, restored the database from the backup file and then renamed the restored database to match the previous database name

SQL Server backup Using Windows command line

My Windows Server 2003 got corrupted and I'm trying to repair it but before that I'm trying to create a backup of my SQL Server databases.
Can anyone please tell me which files do I need to copy from the Windows command line as I'm not familiar with SQL Server. Database files from which I can restore data.
Its an old server but data is important.
And also if I repair Windows server 2003 using repair disk will it effect on SQL Server files ?
http://postimg.org/image/5jsstbqmd/
When I start server I get this error.
You can use this SQL command (adapt to your specific case):
--Back up the files in SalesGroup1:
BACKUP DATABASE YourDBName
TO DISK = 'Z:\SQLServerBackups\BackupFileName.bck';
GO
See Backup in Transact-SQL for more details.
To run a SQL script from command line:
sqlcmd -S myServer\instanceName -i C:\myScript.sql
Before messing with anything, you could take a complete image of your hard drive using a tool such as clonezilla.
I would get to the root of your disk and run
dir /a /s *.mdf
The .mdf file is the file extension that SQL Server uses, and that command will tell you where they are located. The log files are usually in the same directory.
As per your second question, the disk repair will only affect your database files if they are part of the corruption that is happening; which is quite likely if you were running a high I/O database when it crashed. I would definitely try and copy those files off before running a disk check.

Using SQL Server Management Studio Express to Backup DB

I am wanting to backup a SQl Server 2005 db at a remote site (ie. to ultimately have a backup file of the db here locally on my machine).
Can this be done using SQL Server Management Studio Express ? I have this installed and running.. but cannot seem to find a way of backing up using it.
If this isn't possible, how do I create a backup of my remote db some other way ?
Thank you,
Bazza
It should be possible, right click on the database, select Tasks->Backup.
The other good option is the bcp command line utility. If your backup needs to be done regularly it's a better option since you can use it in a bacth file or script and create a scehduler task for it.
I'm not sure, however if you have remote access to the system concerned you should be able to run a SQLCMD and issue the backup from the command line.
1) create a script called say backup.sql
USE [master]
GO
BACKUP DATABASE [somedatabase]
TO DISK = N'C:\somedatabase.bak'
WITH NOFORMAT,
INIT,
NAME = N'Full Database Backup of somedatabase',
SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
2) issue:
sqlcmd -U username -P password -i backup.sql
Then copy the file over.
Unfortunately, I can't answer your specific question regarding SSMS Express - I've not used the tool extensively. However, I do know that you can open a New Query window and issue a BACKUP DATABASE command. An example of this would be:
backup database <dbname,,> to disk='c:\mydbbackup.bak';
You could then use standard methods (such as FTP) to get the file copied locally. Hope that helps!
This works in SSMS 2008 Express:
Right-click the database name in object explorer > Tasks > Backup…
Select "Full" (should already be default), enter a name, and at the bottom click "Add" and create the file to which you want to back up.
Run the backup.
Copy the file to your local machine.
Connected to the local machine, select the "Databases" node in Object Explorer > Restore Database…
Now name the new database, select "from device" and choose the backup file from which to create the new database, and go.
Done.

Resources