I am using SQL Server Express and I have a stored procedure for taking backups which I took from Microsoft: How to schedule and automate backups of SQL Server
Then I use Windows Task Scheduler for taking the backups.
I have a task running on 2 AM which takes a full backup using command:
sqlcmd -S SERVER\MSSQLEXPRESS -E -Q "EXEC sp_BackupDatabases #backupLocation='C:\Backups\SQL\TEMP\', #backupType='F'"
Then from 2.30 AM I take a differential backup every hour using command:
sqlcmd -S SERVER\MSSQLEXPRESS -E -Q "EXEC sp_BackupDatabases #backupLocation='C:\Backups\SQL\TEMP\', #backupType='D'"
Now here I have a problem, the full backup works but after that I see no new added backup files in my folder. When I open the server I see a command prompt from the differential backup running asking to overwrite the FULL backup files.
I click A from ALL and then it works. The hour after again, a command prompt to overwrite previous DIFF and FULL backup files.
How can I set this to always be ALL or how can I disable this?
Related
I am trying to restore a SQL database using .bak file on an Ubuntu server where SQL Developers is installed.
I used the following command line:
sqlcmd -S localhost,1433 -U SA -Q "RESTORE VERIFYONLY JCIHistorianDB
FROM DISK = '/home/test_db.bak' WITH MOVE 'testDB_Data' TO
'/var/opt/mssql/data/test_db.mdf', MOVE 'testDB_Log' TO
'/var/opt/mssql/data/test_db.ldf'"
As per following, the result is successful:
RESTORE DATABASE successfully processed 528668 pages in 845.191 seconds
However the database data is around half of the size it should be. It's not coming from the .bak file as the restoration from the same file on a windows instance was all good.
Do you have any ideas why this happened? I also have enough space on the Ubuntu Server.
Thank you very much for your time.
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.
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.
I am using PostgreSQL 8.4 on my Windows Server 2012 box. I have made a configuration with pgagent for job scheduling. I need to schedule an auto backup on a daily basis on my system using with job scheduling. I searched the net and created a batch file and located the file path in job scheduling.
If I run the batch file on my server then it works fine, but when I call it using scheduling in PostgreSQL then it goes in the running stage, but does not give any kind of result.
Below is the command I used for taking backup:
"c:\Program Files (86)\path\to\bin" pg_dump.exe -i -h hostname -U username -F c -b -v -f "backup\file\path\filename.backup" databasename
This command is working fine on the command prompt and when calling the batch file, but does not give any output from PostgreSQL job scheduling.
Does anyone have any idea about this kind of issue?
I am using a SQL Server database. I have these SQL queries:
Delete from TableA;
Delete from TableB;
Delete from TableC;
Delete from TableD;
Delete from TableE;
Is it possible to run these scripts using a batch file? The database is a remote database.
Thanks!
Save the commands in a .SQL file, ex: ClearTables.sql, say in your C:\temp folder.
Contents of C:\Temp\ClearTables.sql
Delete from TableA;
Delete from TableB;
Delete from TableC;
Delete from TableD;
Delete from TableE;
Then use sqlcmd to execute it as follows. Since you said the database is remote, use the following syntax (after updating for your server and database instance name).
sqlcmd -S <ComputerName>\<InstanceName> -i C:\Temp\ClearTables.sql
For example, if your remote computer name is SQLSVRBOSTON1 and Database instance name is MyDB1, then the command would be.
sqlcmd -E -S SQLSVRBOSTON1\MyDB1 -i C:\Temp\ClearTables.sql
Also note that -E specifies default authentication. If you have a user name and password to connect, use -U and -P switches.
You will execute all this by opening a CMD command window.
Using a Batch File.
If you want to save it in a batch file and double-click to run it, do it as follows.
Create, and save the ClearTables.bat like so.
echo off
sqlcmd -E -S SQLSVRBOSTON1\MyDB1 -i C:\Temp\ClearTables.sql
set /p delExit=Press the ENTER key to exit...:
Then double-click it to run it. It will execute the commands and wait until you press a key to exit, so you can see the command output.
Check out SQLCMD command line tool that comes with SQL Server. http://technet.microsoft.com/en-us/library/ms162773.aspx
Use the SQLCMD utility.
http://technet.microsoft.com/en-us/library/ms162773.aspx
There is a connect statement that allows you to swing from database server A to server B in the same batch.
:Connect server_name[\instance_name] [-l timeout] [-U user_name [-P password]]
Connects to an instance of SQL Server. Also closes the current connection.
On the other hand, if you are familiar with PowerShell, you can programmatic do the same.
http://technet.microsoft.com/en-us/library/cc281954(v=sql.105).aspx
Different ways:
Using SQL Server Agent (If local instance)
schedule a job in sql server agent with a new step having type as "T-SQL" then run the job.
Using SQLCMD
To use SQLCMD refer http://technet.microsoft.com/en-us/library/ms162773.aspx
Using SQLPS
To use SQLPS refer http://technet.microsoft.com/en-us/library/cc280450.aspx