I have a sqlserver 2017 in an ubuntu 16.04 server working good, so I made a script for backup my database automatically, for this I create a bash file:
sqlcmd -U sa -P xxx -S xxxxx -d COMPART -i /usr/local/bin/SQLRESPALDO1.sql > test.txt
exit
and my .sql file is this:
BACKUP DATABASE [COMPART] TO DISK = N'./COMPART1.Bak' WITH INIT,
NAME = N'COMPART-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
declare @backupSetId as int
select @backupSetId = position from msdb..backupset where database_name=N'COMPART' and backup_set_id=(select max(backup_set_id)
from msdb..backupset where database_name=N'COMPART' )
if @backupSetId is null begin raiserror(N'Verify failed. Backup information for database ''COMPART'' not found.', 16, 1) end
RESTORE VERIFYONLY FROM DISK = N'./COMPART1.Bak' WITH FILE = @backupSetId, NOUNLOAD, NOREWIND
GO
this commands works when I run in terminal with sh SQLRESPALDO1.sh
So for make this recursively I create a crontab job:
50 13 * * * sh /usr/local/bin/SQLRESPALDO1.sh
But cron never execute my file or the part of sqlcmd.
I tried to put another line before the sqlcmd comand and cron execute it correctly, but sqlcmd command no.
the file .sh has all the permissions.
Some one have a clue for this?