AFP548 Changing the world one server at a time.

Using slapconfig -backupdb in a backup script

Home › Forums › OS X Server and Client Discussion › Open Directory › Using slapconfig -backupdb in a backup script

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #369464
    kainewynd2
    Participant

    First item to note: I am competent with bash scripting, but not “good.” If I was good I wouldn’t be asking this question. 🙂

    So, I have a client who was only able to purchase one OD Xserve to use in a AD-OD integration project. Everything is running great (finally), but I would like to be able to pull nightly database backups since we don’t have a replica scenario in place.

    So far I have the following:

    ############################################ 
    #          VARIABLES                       
    ############################################ 
    DATE=`date "+%Y-%m-%d"`
    BPATH="/Volumes/Data/Backup/ODBackup"
    FILENAME="$BPATH/$DATE-backup"
    PASSWORD="blargh"
    
    ############################################ 
    #          WORK                            
    ############################################ 
    /usr/sbin/slapconfig -backupdb $FILENAME
    
    
    /usr/sbin/chmod 700 $FILENAME

    As you can see I am missing one major portion of the code which is where I pass the archive password variable. I know this sort of thing is possible in bash scripting, but I’m not entirely sure what it’s called so I haven’t had any luck looking it up.

    Additionally, I am aware of the security implications of having the archive password in a clear text document and will have permissions set accordingly.

    Thanks in advance.

    –Mike

    #369477
    Dean_Shavit
    Participant

    kainewynd2 wrote:

    First item to note: I am competent with bash scripting, but not “good.” If I was good I wouldn’t be asking this question. 🙂

    So, I have a client who was only able to purchase one OD Xserve to use in a AD-OD integration project. Everything is running great (finally), but I would like to be able to pull nightly database backups since we don’t have a replica scenario in place.

    So far I have the following:

    ############################################ 
    #          VARIABLES                       
    ############################################ 
    DATE=`date "+%Y-%m-%d"`
    BPATH="/Volumes/Data/Backup/ODBackup"
    FILENAME="$BPATH/$DATE-backup"
    PASSWORD="blargh"
    
    ############################################ 
    #          WORK                            
    ############################################ 
    /usr/sbin/slapconfig -backupdb $FILENAME
    
    
    /usr/sbin/chmod 700 $FILENAME

    As you can see I am missing one major portion of the code which is where I pass the archive password variable. I know this sort of thing is possible in bash scripting, but I’m not entirely sure what it’s called so I haven’t had any luck looking it up.

    Additionally, I am aware of the security implications of having the archive password in a clear text document and will have permissions set accordingly.

    Thanks in advance.

    –Mike

    That would be the “expect” command which works interactively with the current tty. Have a look at Andrina’s article on changing local admin passwords (it’s a few years old, but a good illustration on how to use expect).

    #369773
    morgant
    Participant

    For the record, my expect script is as follows (based on the suggestion here):

    #!/usr/bin/expect -f
    
    set date [timestamp -format "%Y-%m-%d"]
    set archive_path "path/to/you/backup/dir"
    set archive_password "password"
    set archive_name "opendirectory_backup"
    
    spawn /usr/sbin/slapconfig -backupdb $archive_path/$archive_name-$date
    expect "Enter archive password"
    send "$archive_password\r"
    expect eof

    Hope that helps others since I’ve not seen one like this actually posted anywhere. I really do wish the serveradmin method worked for me though.

    Edit: Of course, you really want to run put this file in root’s crontab so it runs nightly and also change the permissions to r/w/x for root-only as you’ll be storing the password right in the file.

    #371465
    benhur
    Participant

    Thanks! This worked great.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.