Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Backup name with CURRENT_DATE
Wed, Aug 27 2014 5:41 AMPermanent Link

AndreasL

Hi,

I'm new with ElevateDB an have perhaps a stupid question but I need a hint...

I would lke to create a job for a daily backup. The name should be " backupxyz" plus CURRENT_DATE.

This code doesn't work:

BACKUP DATABASE myDatabase
AS "backupxyz" + CURRENT_DATE TO STORE "myStore"

How to code correctly?

Thanks and best regards
Andreas
Wed, Aug 27 2014 8:51 AMPermanent Link

Aage J.

Maybe this one didn't make it to the NG - resending.


Den 27.08.2014 11:41, skrev AndreasL:
> Hi,
>
> I'm new with ElevateDB an have perhaps a stupid question but I need a hint...
>
> I would lke to create a job for a daily backup. The name should be " backupxyz" plus CURRENT_DATE.
>
> This code doesn't work:
>
> BACKUP DATABASE myDatabase
> AS "backupxyz" + CURRENT_DATE TO STORE "myStore"
>
> How to code correctly?
>
> Thanks and best regards
> Andreas
>




And the error message is ?

I've never used this, but I would first try the concatenation operator
|| (replacing the +), and casting the date to varchar.

--
Aage J.

Wed, Aug 27 2014 11:33 AMPermanent Link

Adam Brett

Orixa Systems

Aage

The correct form is to create a SCRIPT, this can cope with the addition of variables in the form you require:

SCRIPT
BEGIN
 EXECUTE IMMEDIATE
 ' BACKUP DATABASE "MyDatabase" AS
   "MyBU'+CAST(Current_Date AS VARCHAR(10))+'"
   TO STORE "MyStore" INCLUDE CATALOG ';
END

It is important to remember that EDB SQL script is somewhat "type aware", so you cannot simply concatenate a VARCHAR variable to a DATE variable, you need to use the CAST keyword to ensure that the date becomes a VARCHAR with the correct format.

Note the addition of the "Include Catalog" at the end of the statement. This ensures that if the database structure changes you can still use an older backup file to restore the database.
Wed, Aug 27 2014 3:13 PMPermanent Link

Aage J.

Den 27.08.2014 17:33, skrev Adam Brett:
> Aage
>
> The correct form is to create a SCRIPT, this can cope with the addition of variables in the form you require:
>
> SCRIPT
> BEGIN
>    EXECUTE IMMEDIATE
>    ' BACKUP DATABASE "MyDatabase" AS
>      "MyBU'+CAST(Current_Date AS VARCHAR(10))+'"
>      TO STORE "MyStore" INCLUDE CATALOG ';
> END
>
> It is important to remember that EDB SQL script is somewhat "type aware", so you cannot simply concatenate a VARCHAR variable to a DATE variable, you need to use the CAST keyword to ensure that the date becomes a VARCHAR with the correct format.
>
> Note the addition of the "Include Catalog" at the end of the statement. This ensures that if the database structure changes you can still use an older backup file to restore the database.
>

Thank you.  I'm still on an old dbISAM and my post was just trying some
first aid to AndreasL.
Your post should be all he needs, unless he wants to format the date.

--
Aage J.
Wed, Aug 27 2014 7:44 PMPermanent Link

Jeff Cook

Aspect Systems Ltd

Avatar

On 27/08/2014 9:41 p.m., AndreasL wrote:
> Hi,
>
> I'm new with ElevateDB an have perhaps a stupid question but I need a hint...
>
> I would lke to create a job for a daily backup. The name should be " backupxyz" plus CURRENT_DATE.
>
> This code doesn't work:
>
> BACKUP DATABASE myDatabase
> AS "backupxyz" + CURRENT_DATE TO STORE "myStore"
>
> How to code correctly?
>
> Thanks and best regards
> Andreas
>

Hi Andreas

You don't say if there is an error message, but I think your problem is
that CURRENT_Date is not a string.

Try something like :-

CAST(CURRENT_TIMESTAMP AS VARCHAR(17))

I ripped that out of a Job that works for me as below.

Cheer

Jeff
===============================================================

CREATE JOB "DB0000_Saturday"
RUN AS "System"
FROM DATE '2000-01-01' TO DATE '2030-12-31'
DAILY ON SAT
BETWEEN TIME '17:00' AND TIME '20:00'
CATEGORY 'UserBackups'
BEGIN
  DECLARE StoreName VARCHAR;
  DECLARE FileName VARCHAR;
  SET StoreName = 'STORE-DB0000-Backups';
  SET FileName = 'DB0000' + '-' + REPLACE(' ' WITH '_' IN
  REPLACE(':' WITH '' IN CAST(CURRENT_TIMESTAMP AS VARCHAR(17))));
  EXECUTE IMMEDIATE 'BACKUP DATABASE "DB0000" AS "' + FileName + '"
    TO STORE "' + StoreName + '" INCLUDE CATALOG ';
END
VERSION 1.00
ATTRIBUTES 'Cloud=No'
=======================================================================

This creates backups named like this "DB0000-2014-08-07_1750.EDBBkp"
Image