Quick example

Dec 5, 2011 at 5:16 PM

Do you have a quick example for reference. I am new to PS but it is just what I needed.

Thanks!!

Roel

Coordinator
Dec 5, 2011 at 5:52 PM
Edited Dec 5, 2011 at 6:01 PM

Hello Roel,

Thanks for giving psbackup a try. The script aims to aggregate existing copy tools. The first thing you will want to review is the default backup configuration file located in [path_to_psbackup]\conf\default_backup.config. default_backup.config  will be loaded and parsed on each script run if no custom backup configuration file is specified. You can load a different backup configuration file on script run with the -config [path_to_custom_backup_config] argument. Example:

#run script with default configuration file:

PS C:\Users\MyUser> C:\scripts\psbackup_v2\psbackup.ps1

#run script with custom configuration file:

PS C:\Users\MyUser> C:\scripts\psbackup_v2\psbackup.ps1 -config c:\scripts\psbackup_v2\conf\custom_backup.config

 

Lets take a look at the [path_to_psbackup]\conf\default_backup.config file so you can see what some of the configuration options mean:

debug "false" <- this config item will output debug statements to the powershell prompt if true. Default is false

backup.location "C:\MyBackups" <- this is the local or UNC path to your backup storage location.

backup.numToKeep "2" <- how many concurrent unique backups to keep in backup.location. default is 2. When the script next runs, it generates a new backup, and on successful backup completion, will delete the oldest backup to match the number of backups to keep

backup.archive "false" <- Whether to archive your backup. This uses rar.exe to archive the backup after the initial file copy is completed

 

Now, psbackup presently aggregates flat file copies (via robocopy), mysqldump, and sqlcmd. I will only go over robocopy for now, but if you are experiencing issues with any others let me know. Lets look at a sample robocopy line in the configuration file:

ROBOCOPY.EXE "C:\MySourceDirectory" "%DEST%" /E /Z /COPY:ALL %/MP% %/MDL%


psbackup will take this robocopy command and more or less execute it verbatim. The only difference is custom switches enclosed in % characters. Since you do not know the location of the resulting backup, a custom swith/flag %DEST% is used to specify the destination directory during script run. %DEST% is replaced during script run with the destination directory + any subsequent paths found after. Example:

"%DEST%"

becomes

"C:\MyBackups\B1_2011-12-5_0100AM"

explination of available flags:

# %DEST%   : %DEST% is replaced with the backup target directory set in main script when run                         
# %/MP%    : maintains paths from source to %DEST%. Ex: 'C:\dir1\dir2' becomes '%DEST%\dir1\dir2'
# %/MDL%   : stands for "Maintain Drive Letter". Ex: 'C:\dir1\dir2' becomes '%DEST%\C_DRIVE\dir2' combine with %/MP% to maintain paths ex: 'C:\dir1\dir2' becomes '%DEST%\C_DRIVE\dir1\dir2'

Lastly, psbackup will also log to [path_to_psbackup]\logs. Each script run has its own set of log files incase you need to review what was actually backed up. psbackup does not yet delete old log files so this is something you may need to handle presently.

should you have further questions let me know!