Scripting Backups and Restores from Command Line

tahdesign1
Collaborator
Collaborator

Scripting Backups and Restores from Command Line

tahdesign1
Collaborator
Collaborator

I am writing some scripts to lighten the load of my weekly backup testing.

My weekly full backup is developed through the ADMS console and then scheduled through Task Scheduler.

That being said the folder name ends up being VaultBackup_Date_Time. 

 

So since the Date_Time part changes every week, I am thinking that the restore script -Bfolder command would have to be altered every week to match which would negate the advantage of scripting the task.

 

If you look at the script file running the backup it is just stating the upper level folder I have pointed it to but it then makes a sub folder for the backup with the name VaultBackup_Date_Time.

 

So when writing a script for the restore you would use -Bfolder command to point at the folder that contains a backup. So if I pointed this to the upper level folder would it just restore the first VaultBackup_Date_Time folder that it ran into?

 

I try to make sure I move out the previous weeks sub folder but there have been times (on vacation) that I have not so ended up with two VaultBackup_Date_Time folders. So not sure what would happen in that situation.

 

I could answer a lot of these questions by just trial and error since I have a test environment but am hoping to cut my time short if someone here is also scripting out some of these tasks. 

0 Likes
Reply
Accepted solutions (1)
1,261 Views
11 Replies
Replies (11)

paul.gunn
Alumni
Alumni
Accepted solution

Hi,

 

Unfortunately the path given to 'restore' does need to be complete (including the relevant VaultBackup_Date_Time directory). I'm not sure how other people handle determining the path for automated restore purposes.

 

Paul

0 Likes

tahdesign1
Collaborator
Collaborator

Well that's disheartening in the view of scripting this.

 

So I am a little confused then on the -Bfolder command that is used in both backup and restore scripts.

 

Please refer to you help pages on this to see my confusion

Autodesk Vault Command Line Server Console

 

If you look at the examples under backup and restore they both show the -Bfolder command being point to a folder named C:\Backup.

Now by examining my files and what you have stated, we know that the backup process uses that folder and then adds a sub folder named VaultBackup_Date_Time.

 

This is fine in scripting the backup process since we know it will just add the VaultBackup_Date_Time to the stated folder in the script.

 

However, no where in the help does it indicate that the backup process is going to add the VaultBackup_Date_Time folder which in my opinion negates to usefulness of even scripting the restore process. 

 

   

0 Likes

paul.gunn
Alumni
Alumni

Hi,

 

I'm sorry for any confusion regarding the documentation - I agree that it does not spell out the exact behavior. The command line functionality has been like this for many years, so I'm not completely sure the original reasons for this decision. I suspect that having 'backup' specify the parent directory (with the actual backup directory automatically being created) may simplify backup scripts - in that they don't need to manage creation of unique subdirectories per backup. I would not argue that this does complicate automated restore scenarios however.

 

Paul

0 Likes

tahdesign1
Collaborator
Collaborator

Unless some wild card calls can be added in the restore script to make the -B look at a directory that is C:\Backup\VaultBackup_%%_%%, where it accepts whatever is there for %%.

 

Just to clarify what I am trying to do

 

  1. Production ADMS does a full backup on Friday night.
  2. Backup is copied from Production Vault to Test Vault on Saturday night (this is already scripted and tested)
  3. Test Vault restores Friday nights backup (Sunday night)

So then when I come in Monday morning I only have to examine the log to see that Fridays backup has been verify.

0 Likes

paul.gunn
Alumni
Alumni

This stack overflow post has some ideas about working with wildcards that you might find useful. It seems like either the 'change directory' or 'for do' strategy might be useful here .  It does make the valid point though that if you do have multiple matching subdirectories (e.g. multiple vault backups) then things mightn't go so well:

http://stackoverflow.com/questions/8609028/copying-files-with-wildcards-in-the-path

 

Another alternative might be a scripting language like python that has more capabilities. e.g. to find the most recent subdirectory. That might be more involved but would likely be more robust if you did accidentally end up with multiple backups in the parent directory.

 

Paul

0 Likes

tahdesign1
Collaborator
Collaborator
0 Likes

ihayesjr
Community Manager
Community Manager

To clarify, you might be able to use Python outside of Vault to do somethings but customizing the UI isn't tested with Python.




Irvin Hayes Jr
Sr. Product Manager
Autodesk, Inc.

Vault - Under the Hood Blog
0 Likes

tahdesign1
Collaborator
Collaborator

Thanks for clarifying.

 

However, this is all getting to involved for the purpose of scripting a simple recurring task.

Obviously the backups, full or incremented, are scripted and the ADMS console actually produces those for you.

I guess the test restore will just have to stay a manual task.

0 Likes

andrewdroth
Advisor
Advisor

@tahdesign1 I know this is a really old post, but did you ever come up with a method to handle this?

I also want to automate with a recurring task.


Andrew Roth
rothmech.com

YouTube IconLinkedIn Icon

0 Likes

smilinger
Advisor
Advisor

I recommend you switch to Powershell instead of the old DOS batch file as your script language.

For example:

 

$backupFolder = 'E:\_VAULTBACKUP'
$logFolder = 'E:\_RESTORELOG'

$dateString = (Get-Date).ToString('yyyy_MM_dd_hh_mm_ss')
$restoreLog = Join-Path $logFolder "VaultRestore_$dateString.log"

$AdmsConsole = 'C:\Program Files\Autodesk\Vault Server 2021\ADMS Console\Connectivity.ADMSConsole.exe'

# Vault user name and password
$vaultUser = 'administrator'
$vaultPassword = ''

# Find the latest backup folder by folder creation time
$latestBackupFolder = Get-ChildItem $backupFolder -Filter VaultBackup* | Sort-Object CreationTime -Descending | Select-Object -First 1

$arguments = "-Orestore -B$($latestBackupFolder.FullName) -VU$vaultUser -VP$vaultPassword -S -L$restoreLog"

& $AdmsConsole $arguments.Split(' ') | Out-Null

 

 

 

0 Likes

GunnarNilsson
Collaborator
Collaborator

To get rid of the date and time suffix you do like this. After the backup is run rename the folder VaultBackup_2022_01_12_16_04_45 to Vaultbackup with this command:

Move D:\Backupfolder\VaultBackup_* D:\Backupfolder\Vaultbackup

 

Do a robocopy /mir of that renamed folder to the testrestore server

 

Run the restore command on the restore server

0 Likes