Simple script for restoring puppet hosted files from local backup

1,018 views
Skip to first unread message

Kenneth Holter

unread,
Nov 4, 2009, 10:40:09 AM11/4/09
to puppet...@googlegroups.com
 
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
 
 

Luke Kanies

unread,
Nov 9, 2009, 2:51:49 PM11/9/09
to puppet...@googlegroups.com

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

Reply all
Reply to author
Forward
0 new messages