Thus far I have been trying to successfully develop a script which does the following when comparing a ZFS volume to a snapshot:
Gives the new files (missing from snapshot)
Gives the missing files (in snapshot but not current volume)
Gives the potentially changed files
I've done it to no avail. Several times over I've been tweaking this to get it to work, first eliminating most non-printable characters for the comparison (this may be creating duplicate entries when fed through comm with both columns 1 and 2). The problem with that is those non-printable characters evidently make a huge difference to ls -s. Perhaps somebody could help me with this script:
Gives the new files (missing from snapshot)
Gives the missing files (in snapshot but not current volume)
Gives the potentially changed files
I've done it to no avail. Several times over I've been tweaking this to get it to work, first eliminating most non-printable characters for the comparison (this may be creating duplicate entries when fed through comm with both columns 1 and 2). The problem with that is those non-printable characters evidently make a huge difference to ls -s. Perhaps somebody could help me with this script:
Code:
#!/usr/local/bin/bash
LC_ALL=C;
export LC_ALL=C;
LANG=en_US.UTF-8;
export LANG=en_US.UTF-8;
sudo mount -t mfs -o rw,noatime,-s8M md /mnt/rd;
touch /mnt/rd/1 /mnt/rd/2;
#cd $1 && find . -type f | tr -d \000 | sort -o /mnt/rd/1;
cd $1 && find . -type f | tr -d \000 | sort -o /mnt/rd/1;
#cd $1/.zfs/snapshot/$2 && find . -type f | tr -d \000 | sort -o /mnt/rd/2;
cd $1/.zfs/snapshot/$2 && find . -type f | sort -o /mnt/rd/2;
echo -ne "New files: \n" >> /mnt/rd/nmf;
comm -23i /mnt/rd/1 /mnt/rd/2 >> /mnt/rd/nmf;
echo -ne "Missing files: \n" >> /mnt/rd/nmf;
comm -13i /mnt/rd/1 /mnt/rd/2 >> /mnt/rd/nmf;
echo -ne "Most likely changed files: \n" >> /mnt/rd/nmf;
comm -12i /mnt/rd/1 /mnt/rd/2 >> /mnt/rd/same;
#do ls -s (same output as du) and get the file sizes
while read LINE; do
cd $1 && echo -ne "size: `ls -s "$LINE"`\n"
cd $1/.zfs/snapshot/$2 && echo -ne "size: `ls -s "$LINE"`\n"
done < /mnt/rd/same >> /mnt/rd/3;
#this is for the current
#do ls -s (same output as du) and get the file sizes
#cd $1/.zfs/snapshot/$2 && while read LINE; do
# ls -s $1/.zfs/snapshot/$2/"$LINE"
#done < /mnt/rd/same >> /mnt/rd/4;
#this is for the snapshot
uniq -ui /mnt/rd/3 /mnt/rd/uniqs
cat /mnt/rd/uniqs >> /mnt/rd/nmf; #find unmatched sizes
cat /mnt/rd/nmf;
cd ~;
sudo umount /mnt/rd;
MDS=`sudo mdconfig -l`;
for i in $MDS;
do sudo mdconfig -d -u $i;
done;