Reputation: 10820
I am writing a C# app that would call the isql.exe
with appropriate arguments.
The interface that I need to conform to:
public void Backup(string serverName, string databaseName, string userName, string password, string backupDestinationPath);
public void Restore(string serverName, string databaseName, string userName, string password, string restoreSourcePath);
I have already implemented this for MSFT SQL Server 2008. They have great documentation, such as: http://technet.microsoft.com/en-us/library/ms186865.aspx
I came up with ways to do it (for SQL Server):
BACKUP DATABASE MY_DB
TO DISK = 'C:\Temp\MY_DB.bak'
WITH INIT, SKIP, NOFORMAT, NOUNLOAD,
CHECKSUM, STOP_ON_ERROR,
NAME = 'MY_DB.bak',
DESCRIPTION = 'Backup of MY_DB.';
RESTORE DATABASE MY_DB
FROM DISK = 'C:\Temp\MY_DB.bak'
WITH REPLACE, RECOVERY;
And call it like so (Windows batch file syntax):
sqlcmd -E -S %SERVERNAME% -U %USER% -P %PASSWORD% -d master -Q "%SQL_BACKUP_CMD%"
I have not been able to find much online about how to do this for SyBase.
EDIT:
I can now do this from the command line. First I create a file named syb_bak.sql containing:
dump database mydb to "D:\Temp\mydb.bak"
go
exit
Then I call it on the command line in one of two ways:
isql.exe -S {serverAlias} -U {user} -P {password} -i syb_bak.sql
isql.exe -S {serverAlias} -U {user} -P {password} < syb_bak.sql
Optionally I can use the -o
flag or an output redirect >
to grab the output.
Everything works great, except that, to my surprise, the backup file is being dumped on the server side and not client.
Upvotes: 2
Views: 21047
Reputation: 2088
Dump database command
f.e.
dump database DB to "/dev/nrmt0" with init
Restore database
f.e.
load database DB from "/dev/nrmt0"
Upvotes: 4