2

I am creating an installer in order to update a service. My idea is:

  1. Stop Service
  2. Backup all files and folders in a folder named backup.
  3. Remove all files and folders
  4. Copy (install) new files and folders
  5. Copy some files (configuration files) from backup overwriting new files created.

This is my code actually:

[Run]
;1. Stop service
Filename: "{sys}\sc.exe"; Parameters: "stop ""myService"

[Files]
;2. Create temporally backup
Source: {app}\*; Excludes: "backup"; DestDir: {app}\backup\backup{code:GetTodaysName}; \
    Flags: external skipifsourcedoesntexist recursesubdirs createallsubdirs

;Install new version.
Source: "{#MyInstalerPath}\bin\*"; DestDir: "{app}"; \
    Flags: ignoreversion recursesubdirs createallsubdirs

;Restore config files.
Source: "{app}\backup\backup{code:GetTodaysName}\myService.Configuration.xml"; \
    DestDir: "{app}"; Flags: external 
[Code]
var
  TodaysName : String;

function GetToday : String;
begin
  Result := GetDateTimeString ('yyyymmddhhnnss', '-', #0);
end;

function GetTodaysName (Param: String): String;
begin
  if ('' = TodaysName) then
  begin
    TodaysName := GetToday ();
  end;
  Result := TodaysName;
end;

I have problems in parts 2 and 3. I should avoid backup folder in backup process, but I can't use both Excludes and external.

Anyone can help with this issues? Thanks

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Alvaro
  • 33
  • 4

1 Answers1

2

You have to use Pascal Script to copy/backup the files, if you want to exclude some.

See Inno Setup: Backup external file before install delete section

Except that you need to modify the DirectoryCopy function from Inno Setup: copy folder, subfolders and files recursively in Code section to exclude the backup folder itself.

Just modify this line:

if (FindRec.Name <> '.') and (FindRec.Name <> '..') then

to

if (FindRec.Name <> '.') and (FindRec.Name <> '..') and
   (CompareText(FindRec.Name, 'backup') <> 0) then

Though if the backup is "temporary", why don't you backup the files to {tmp}, instead of a subfolder of {app}? Then you won't have to exclude anything.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992