Skip to content

Instantly share code, notes, and snippets.

@Chris2048
Created March 10, 2013 21:49
Show Gist options
  • Save Chris2048/5130622 to your computer and use it in GitHub Desktop.
Save Chris2048/5130622 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Usage: ./make-lsLR.sh
#
# Purpose:
# to make a file that is parseable for recovering
# a filled /lost+found directory by parsing
# filesize, md5sum, permisions and path+filename
#
# Author: Ingo Juergensman - http://blog.windfluechter.net
# License: GPL v2, see http://gnu.org for details.
#
# first: get all directories
# fail silently when a Xen Kernel is loaded
if [ `uname -r | grep xen-686` ]; then
exit 0
fi
# check whether a full backup is running on this host or not
check_full=`su - backuppc -c "/usr/share/backuppc/bin/BackupPC_serverMesg status jobs muaddib" | grep '"type" => "full"'`
while [ -n "$check_full" ]; do
check_full=`su - backuppc -c "/usr/share/backuppc/bin/BackupPC_serverMesg status jobs muaddib" | grep '"type" => "full"'`
# echo "Fullbackup running"
sleep 300
done
nice -20 find / -path /sys -prune -o \
-path /proc -prune -o \
-path /var/lib/backuppc -prune -o \
-path /var/spool/squid -prune -o \
-path /media -prune -o \
-path /mnt -prune -o \
\( -name .AppleDouble -o -name .AppleDB -o -name .AppleDesktop \) -prune -o \
-type d -printf "%U:%G %#m " -print > /root/ls-md5sum-dirs.txt.new
# next: get all relevant information
nice -20 find / -path /sys -prune -o \
-path /proc -prune -o \
-path /var/lib/backuppc -prune -o \
-path /var/spool/squid -prune -o \
-path /media -prune -o \
-path /mnt -prune -o \
\( -name .AppleDouble -o -name .AppleDB -o -name .AppleDesktop \) -prune -o \
-type f -printf "%s %U:%G %#m " \
-exec nice -15 md5sum {} \; | tr -s " " > /root/ls-md5sum-files.txt.new
# keep a backup file
if [ -e /root/ls-md5sum-dirs.txt ]; then
#echo "mv dirs.1"
mv /root/ls-md5sum-dirs.txt /root/ls-md5sum-dirs.txt.1
if [ -e /root/ls-md5sum-dirs.txt.1.gz ]; then
#echo "rm dirs"
rm /root/ls-md5sum-dirs.txt.1.gz
fi
gzip -9 /root/ls-md5sum-dirs.txt.1
fi
if [ -e /root/ls-md5sum-files.txt ]; then
#echo "mv files.1"
mv /root/ls-md5sum-files.txt /root/ls-md5sum-files.txt.1
if [ -e /root/ls-md5sum-files.txt.1.gz ]; then
#echo "rm files"
rm /root/ls-md5sum-files.txt.1.gz
fi
gzip -9 /root/ls-md5sum-files.txt.1
fi
mv /root/ls-md5sum-dirs.txt.new /root/ls-md5sum-dirs.txt
mv /root/ls-md5sum-files.txt.new /root/ls-md5sum-files.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment