...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#!/bin/bash # Location of the fcrepo home directory FCREPO_HOME=/var/lib/tomcat7/fcrepo4-data # Destination Directory BACKUP_TO=/home/vagrant/backup # Backup exact (without the structural changes introduces by Python verfication script). # (Additional temporary storage is used, if true) BACKUP_EXACT=true # Max Backup Attempts on failure ATTEMPTS=10 echo `date`" $0: fcrepo home dir: $FCREPO_HOME" echo `date`" $0: backup dir: $BACKUP_TO" echo `date`" $0: max attempts on failure: $ATTEMPTS" if [ ! -d $BACKUP_TO ]; then mkdir $BACKUP_TO fi LEVELDB_DIR=fcrepo.ispn.repo.cache DATA_DIR=dataFedoraRepository backup_succeeded=false attempts=$ATTEMPTS echo `date`" $0: Backing up leveldb." while [ $attempts -gt 0 ]; do MANIFEST_FILE=`ls $FCREPO_HOME/$LEVELDB_DIR/$DATA_DIR/MANIFEST-*` MANIFEST_MD5=`md5sum $MANIFEST_FILE` rm -rf $BACKUP_TO/$LEVELDB_DIR"-tmp" cp -r $FCREPO_HOME/$LEVELDB_DIR $BACKUP_TO/$LEVELDB_DIR"-tmp" copy_success=$? MANIFEST_FILE_POST_BACKUP=`ls $FCREPO_HOME/$LEVELDB_DIR/$DATA_DIR/MANIFEST-*` MANIFEST_MD5_POST_BACKUP=`md5sum $MANIFEST_FILE_POST_BACKUP` if [ "$MANIFEST_MD5" = "$MANIFEST_MD5_POST_BACKUP" ] && [ "$copy_success" = "0" ]; then backup_succeeded=true break; fi attempts=$((attempts - 1)) echo `date`" $0: leveldb manifest changed during backup process! $attempts attempts remaining." done if [ "$backup_succeeded" = false ]; then echo `date`" $0: Failed to backup with a consistent leveldb manifest!" else echo `date`" $0: Backup created and verified leveldb manifest consistency!" fi if [ "$BACKUP_EXACT" = true ]; then rm -rf $BACKUP_TO/$LEVELDB_DIR"-unchanged" cp -r $BACKUP_TO/$LEVELDB_DIR"-tmp" $BACKUP_TO/$LEVELDB_DIR"-unchanged" fi backup_repaired=false # Verify and repair using python script python verify_leveldb.py $BACKUP_TO/$LEVELDB_DIR"-tmp"/$DATA_DIR if [ "$?" != "0" ]; then echo `date`" $0: Discovered backup corruption! Attempting to repair!" python repair_leveldb.py $BACKUP_TO/$LEVELDB_DIR"-tmp"/$DATA_DIR if [ "$?" != "0" ]; then echo `date`" $0: Backup repair failed!" else python verify_leveldb.py $BACKUP_TO/$LEVELDB_DIR"-tmp"/$DATA_DIR if [ "$?" != "0" ]; then echo `date`" $0: Backup repair failed!" else echo `date`" $0: Backup repair succeeded!" backup_repaired=true backup_succeeded=true fi fi else echo `date`" $0: Backup passed corruption verification!" fi if [ "$backup_succeeded" = true ]; then rm -rf $BACKUP_TO/$LEVELDB_DIR if [ "$BACKUP_EXACT" = true ] && [ "$backup_repaired" = false ]; then mv $BACKUP_TO/$LEVELDB_DIR"-unchanged" $BACKUP_TO/$LEVELDB_DIR else mv $BACKUP_TO/$LEVELDB_DIR"-tmp" $BACKUP_TO/$LEVELDB_DIR fi fi |
The following script can be used to verify a leveldb cache for corruptions:
...