This project has moved. For the latest updates, please go here.

Multiple save to destination and date stamp

Feb 8, 2016 at 12:51 AM
First of all great little backup program. IS there a way to set the back up so that it performs say 7 backups before it replaces them and also time stamp them ?

I backing up to a network NAS

it would be something like
Q://FILESERVER/BACKUPS/USER
Coordinator
Feb 8, 2016 at 6:02 AM
Hello,
you can achieve this by a little script.
Use the post-backup-cmd field to enter the path to the script.
An example is shown here:
https://outlookbackupaddin.codeplex.com/wikipage?title=Script%20collection
--> "keen last n backups"

Kind regards,
Thomas
Feb 8, 2016 at 4:03 PM
Edited Feb 8, 2016 at 5:47 PM
How do I acheive and timestamp? would that be one script?

would I create a new .bat file and use it to call both the date stamp and achieve bat? using a "call Command.bat"
Coordinator
Feb 8, 2016 at 8:46 PM
Hello,
you can use the first script to add the date.
Afterwards you can add a command which deletes files older than n days
(e.g. with the command "forfiles" as shown here: http://ss64.com/nt/syntax-delolder.html

Just put all the necessary commands within one bat-file. This would be the easiest way.

Kind regards,
Thomas
Feb 9, 2016 at 3:04 PM
Edited Feb 9, 2016 at 3:06 PM
Couldnt I just make a new .bat and name it, call.bat

and use that to run the other scripts

call.bat file
@echo off

call append_date.bat
call keep_n_backups.bat

endlocal
Or would that cause a confilct?

If not could I just call one script and run it for the two scripts below not sure how to code it nly?

append_date
@ECHO OFF
rem set backup folder here
cd /Q Q:\Main\Backup\outlook

setlocal EnableDelayedExpansion
set dt=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%

rem iterate over all files and rename them
FOR /F "delims=" %%I IN ('DIR *.pst *.ost /B') DO (
set x=%%I
ren "!x!" "!x:~0,-4!_%dt%.bak"
) 

endlocal
Then this one

keep_n_backups.bat
@echo off
setlocal enableextensions enabledelayedexpansion

rem set max no of backups to keep and backup folder
set MAX_BACKUP=5
cd /Q Q:\Main\Backup\outlook

rem set default revision no to 0
set rev=0

rem read last revision no if exists
if exist revision.txt (
    for /f "delims=" %%a in (revision.txt) do (
        set rev=%%a
    )
)

rem calculate next revision no
Set /A rev=!rev!+1
Set /A rev=!rev! %% !MAX_BACKUP!

rem find pst- and osts-files and rename them
FOR /F "delims=" %%I IN ('DIR *.pst *.ost /B') DO (
    set x=%%I
    if exist "!x:~0,-4!_!rev!.bak" del "!x:~0,-4!_!rev!.bak"
    ren "!x!" "!x:~0,-4!_!rev!.bak"
) 

rem save current revision no
echo !rev! > revision.txt

endlocal

How would I join them to run?
Coordinator
Feb 9, 2016 at 9:10 PM
Hello,
you mainly want to add the date and afterwards delete files older than n days.
So you can just use:
@ECHO OFF
cd /D d:\outlookbackup
setlocal EnableDelayedExpansion
set dt=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%

FOR /F "delims=" %%I IN ('DIR *.pst *.ost /B') DO (
set x=%%I
if exist "!x:~0,-4!_%dt%.bak" del "!x:~0,-4!_%dt%.bak"
ren "!x!" "!x:~0,-4!_%dt%.bak"
) 

rem delete older than 5 days
forfiles -m *.pst /D -5 /C "cmd /c del @path"
forfiles -m *.ost /D -5 /C "cmd /c del @path"
Adjust path and number of days accordingly.
Also take into account that line 4 is depending on your OS language.
Verify at command prompt via:
echo %DATE:~6,4%%DATE:~3,2%%DATE:~0,2%

Kind regards,
Thomas
Feb 10, 2016 at 1:18 AM
Edited Feb 10, 2016 at 1:20 AM
Ok I must be doing somethig wrong
When I choose my path I used this for the original backup path to my NAS:

\Fileserver\main\BACKUP\CD-OPTI9020

as you can see it the picture below:
Image

it backups Perfect every time,
so what should my script or path look like for this script here below:
@ECHO OFF
rem set backup folder here
cd /D d:\outlookbackup

setlocal EnableDelayedExpansion
set dt=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%

rem iterate over all files and rename them
FOR /F "delims=" %%I IN ('DIR *.pst *.ost /B') DO (
set x=%%I
ren "!x!" "!x:~0,-4!_%dt%.bak"
) 

endlocal
It says my path and directory are incorrct..
Coordinator
Feb 10, 2016 at 6:04 AM
Hello,
you must change the location in line 3:
cd /D <put path here>

The path you showed doesnt look like a windows path.
Path usually starts with letter e.g. d: or double backslash \

Kind regards.
Thomas
Feb 11, 2016 at 1:09 AM
ThomasHoffmann wrote:
Hello,
you must change the location in line 3:
cd /D <put path here>

The path you showed doesnt look like a windows path.
Path usually starts with letter e.g. d: or double backslash \

Kind regards.
Thomas
Ok Here is what I did butit still failed ,


I did what you said to the script:
@ECHO OFF
rem set backup folder here
cd /D \\FILESERVER\OUTLOOK\CD-OPTI9020
setlocal EnableDelayedExpansion
set dt=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%

rem iterate over all files and rename them
FOR /F "delims=" %%I IN ('DIR *.pst *.ost /B') DO (
set x=%%I
ren "!x!" "!x:~0,-4!_%dt%.bak"
) 

endlocal
And I got this message:

Image


THEN I tried to MAP the network drive to Z:\
@ECHO OFF
rem set backup folder here
cd /D Z:\
setlocal EnableDelayedExpansion
set dt=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%

rem iterate over all files and rename them
FOR /F "delims=" %%I IN ('DIR *.pst *.ost /B') DO (
set x=%%I
ren "!x!" "!x:~0,-4!_%dt%.bak"
) 

endlocal
Mapped it fine showed up in the drive area as you can see in picture below:

Image


Got this error message here below:

Image

SO what am I doing wrong?
The backups work fine but the scripts are failing .....Frustrating...
Coordinator
Feb 11, 2016 at 6:30 AM
Hello,

please check the backup settings within outlook.
You still use UNC path in the backup settings.
Please also use letter Z: within the backup configuration in outlook.

Kind regards,
Thomas
Feb 11, 2016 at 11:37 PM
Ok here is what I tried again....

The computer is mapped to see the _Z:_ drive in the drives area..

placed it to _Z:_

in both the outlook settings and script
even tried _Z:_ in outlook and the \Fileserver\outlook\CD-OPTI9020 setting in the script file

neither worked here are pics of the outlook setup and the error I got when I tried to run it in Z drive ....

All though it made the backup every time either way if mapped or not if I used _Z:_ or the fileserver settings, BUT the script append date script keep failing..

Image



Image
Feb 12, 2016 at 1:39 AM
Edited Feb 12, 2016 at 2:58 AM
__Ok I figured it out..
__

I needed to change the cd /D command to pushd then added the popd command at the end to cleanup temp


I also could NOT get the append_date script to work

So here is how it looks now and does work:
@echo off
setlocal enableextensions enabledelayedexpansion

rem set max no of backups to keep and backup folder
set MAX_BACKUP=5
pushd \\FILESERVER\OUTLOOK\JR-OPTI9020


set rev=0

rem read last revision no
if exist revision.txt (
    for /f "delims=" %%a in (revision.txt) do (
        set rev=%%a
    )
)
Set /A rev=!rev!+1
Set /A rev=!rev! %% !MAX_BACKUP!

rem find pst-file and rename
FOR /F "delims=" %%I IN ('DIR *.pst *.ost /B') DO (
    set x=%%I
    if exist "!x:~0,-4!_!rev!.bak" del "!x:~0,-4!_!rev!.bak"
    ren "!x!" "!x:~0,-4!_!rev!.bak"
) 

echo !rev! > revision.txt

popd \\FILESERVER\OUTLOOK\JR-OPTI9020

endlocal
How can I join 2 scripts into one such as the backup_additional_settings.bat and the keep_n_backups.bat ??

I am also not sure if I used the popd command correctly eventhough I get no errors.

...
Feb 13, 2016 at 8:32 PM
Ok I fugured it out running both failes..thanks anyway!
Marked as answer by johnbor on 2/13/2016 at 12:32 PM
Coordinator
Feb 13, 2016 at 8:52 PM
Hi!
You can just append the second script to the first script.
Alternatively you can use "call" command which starts a second script.

Kind regards,
Thomas