Kenneth Holter
2009-Nov-04 15:40 UTC
[Puppet Users] Simple script for restoring puppet hosted files from local backup
Hi. I found this script to retrieve backed up puppet hosted files: http://markmail.org/message/nybqh3be7bcge33h ..and made some adjustsments. I''ve pasted the script below in case anyone else are in need of such a script: --- snip --- #!/bin/bash file=$1 BUCKETDIR=$( puppetd --configprint clientbucketdir ) PREFIX="* " entries_found=0 echo "Searching for local backups of file $file (this may take some time)..." for f in $( find $BUCKETDIR -type f -name paths -exec grep -l $file {} \; |xargs -r ls -t); do md5sum=$( basename $(dirname $f)) filename=$(< $f ) modify_time=$(stat --format ''%y'' $f) echo -e "$filename\t$md5sum\t$modify_time" entries_found=1 done if [ $entries_found -eq 1 ]; then echo "" echo "Horray, backup(s) were found!" echo "* To view the contents of the file, issue this command: \"filebucket -b /var/lib/puppet/clientbucket get <md5sum>\"" echo "* To restore the file, issue this command: \"filebucket restore -b /var/lib/puppet/clientbucket /path/to/new/file <md5sum>\"" else echo "No entries were found. Exiting." --- snip --- Note that the script retrieves files only from the local backup directory. I added the "-r" argument to xargs so that the loop structure would not run unless the "find" command actually find a match. Without the "-r" switch, the loop would run even if you pasted a invalid file name, which for me caused unexpected results. Regards, Kenneth --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Luke Kanies
2009-Nov-09 19:51 UTC
[Puppet Users] Re: Simple script for restoring puppet hosted files from local backup
On Nov 4, 2009, at 7:40 AM, Kenneth Holter wrote:> > Hi. > > I found this script to retrieve backed up puppet hosted files: http://markmail.org/message/nybqh3be7bcge33h > > ..and made some adjustsments. I''ve pasted the script below in case > anyone else are in need of such a script: > > --- snip --- > #!/bin/bash > file=$1 > BUCKETDIR=$( puppetd --configprint clientbucketdir ) > PREFIX="* " > entries_found=0 > echo "Searching for local backups of file $file (this may take some > time)..." > for f in $( find $BUCKETDIR -type f -name paths -exec grep -l $file > {} \; |xargs -r ls -t); > do > md5sum=$( basename $(dirname $f)) > filename=$(< $f ) > modify_time=$(stat --format ''%y'' $f) > echo -e "$filename\t$md5sum\t$modify_time" > entries_found=1 > done > if [ $entries_found -eq 1 ]; then > echo "" > echo "Horray, backup(s) were found!" > echo "* To view the contents of the file, issue this command: > \"filebucket -b /var/lib/puppet/clientbucket get <md5sum>\"" > echo "* To restore the file, issue this command: \"filebucket > restore -b /var/lib/puppet/clientbucket /path/to/new/file <md5sum>\"" > else > echo "No entries were found. Exiting." > --- snip --- > > Note that the script retrieves files only from the local backup > directory. I added the "-r" argument to xargs so that the loop > structure would not run unless the "find" command actually find a > match. Without the "-r" switch, the loop would run even if you > pasted a invalid file name, which for me caused unexpected results.Note that there''s a ''filebucket'' script that is actually in the bin directory in the Puppet repo. -- I hate to advocate drugs, alcohol, violence, or insanity to anyone, but they''ve always worked for me. -- Hunter S. Thompson --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---