0

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?

  • It's probably not in the `$PATH` when run by `cron`, since your profile isn't executed. Use the full path to `sqlcmd`. – Barmar Aug 28 '19 at 19:13
  • `cron` sends email with error messages, unless you disable this in the crontab. Did you check the user's email? – Barmar Aug 28 '19 at 19:14
  • Thank you Barmar! using the full path it works. simple like that. P.S: Sorry if the question is duplicated I didnt consider that because I though my problem was with sqlcmd – Diego Chilomer Aug 28 '19 at 21:51

0 Answers0