how can I backup a file

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
amst
Newbie
Posts: 1
Joined: Tue May 18, 2004 5:22 pm
Location: Pusan, South Korea

how can I backup a file

Post by amst » Tue May 18, 2004 5:53 pm

Dear everyone,

I am a newbie in programming. I need a macro scheduler script to bakup a file (eg "calendar.db") into, first time, "calendar.db01", second time "calendar.db02", third time "calendar.db03" whenever I execute a script called "calendar.scp"

I have a calendar program. When I put in birthdays, appointments etc, it shows such events on the calendar. The data file is "calendar.db" made by the program. Here I made a macro scheduler script called "calendar.scp" to backup this data file.

It shows:

copyfile>c:\program files\calendar\calendar.db,c:\databackup\calendar\calendar.db

But this is not enough for me. I should do something more in this script. Here what I want is that I want to keep the old ones with a number in sequence such as calendar.db01, calendar.db02, calendar.db03 and so on whenever I run the script.

What I should do? Please help me. I don't know programming. Thank you very much in advance.

Howard

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue May 18, 2004 10:14 pm

Determine how many copies you want to keep. Example = 10
Delete the oldest file after you have 10 copies.
Rename the old files by increasing the counts from 1-10.
Copy the current file to file number 1.

Do something like this....(Syntax is no good here, this is quick and dirty concept only. No timetosay to make the script loop right now.)

IfFileExists>FileName.10, Then Delete FileName.10
Let>MF_RENAME=1
IfFileExists>FileName.9, Then MoveFile> FileName.09 to FileName.10
IfFileExists>FileName.8, Then MoveFile> FileName.09 to FileName.9
IfFileExists>FileName.7, Then MoveFile> FileName.09 to FileName.8
IfFileExists>FileName.6, Then MoveFile> FileName.09 to FileName.7
IfFileExists>FileName.5, Then MoveFile> FileName.09 to FileName.6
IfFileExists>FileName.4, Then MoveFile> FileName.09 to FileName.5
IfFileExists>FileName.3, Then MoveFile> FileName.09 to FileName.4
IfFileExists>FileName.2, Then MoveFile> FileName.09 to FileName.3
IfFileExists>FileName.1, Then MoveFile> FileName.09 to FileName.2
Let>MF_RENAME=0
Copy FileName.db to FileName.1

You need to make a loop that starts at 10, and counts down to 0 to cycle through and count down to do the MoveFile on the file names. You don't need all the lines I showed here, only need one MoveFile line with variables. You could also do a MoveFile/CopyFile by itself, but Renaming is faster. If you use CopyFile, be sure to Let>CF_OVERWRITE=1.

Hope this is enough to get you started. Someone else may have the time to do the script properly for you........
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu May 20, 2004 1:04 pm

Hello amst. Good job. Glad to see that this worked for you.

Your reply was sent to me as PM, but I have provided it here. I believe that all forum responses should be made to the forum so that we can all benefit from the exchanges:
Dear Bob,
Thanks again and the note. I made it work but not a good one though.

--------------------------------------------------
DeleteFile>calendar.db10

Let>MF_RENAME=1
MoveFile>calendar.db09,calendardb10
MoveFile>calendar.db08,calendardb09
MoveFile>calendar.db07,calendardb08
MoveFile>calendar.db06,calendardb07
MoveFile>calendar.db05,calendardb06
MoveFile>calendar.db04,calendardb05
MoveFile>calendar.db03,calendardb04
MoveFile>calendar.db02,calendardb03
MoveFile>calendar.db01,calendardb02
MoveFile>calendar.db,calendardb01

rem Let>MF_RENAME=0
CopyFile>c:\program files\calendar\calendar.db,c:\dataall\calendar\calendar.db
---------------------------------------------------------------------

However, Bob, I don't know "Let>MF_RENAME=1" command. My macro scheduler is v 7.0 and does not show such a command or system variable. I guess it is a command to overwrite when move(=rename) a file (1) and not overwrite (0). If my guess is right, I want to know v 7.0 has such function.

As above, I run the script 10 times, it works as I expected. 10 data files are made with a number at its end.

I will post when I solve this "Let>MF_RENAME=1" question.

Thanks again for giving a general idea to solve my problem.


Re the comment inside that PM:
I don't know "Let>MF_RENAME=1" command.
This was added to Version 7.2.037. Current version is 7.2.050. See the Help section on MoveFile for explanation of MoveFile and how to use MF_RENAME to Rename a file. MoveFile will still do the renaming, but it actually does a rewrite of the file, vs. a rename only, so the time to do this can be much longer based on the length of the file.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts