使用与 shell 脚本中的 md5sum 比较的差异备份问题

Differential backup issue using comparison with md5sum in shell script

你好,我有一个简短的问题。我正在尝试实施差异备份,但我遇到问题的地方是比较从 md5sum.txt 到 diffmd5.txt

的散列

我收到以下错误:

目前该命令正在运行并且没有给出任何错误,但是文件没有被替换并且没有备份任何文件

#!/bin/bash
bkdest="/home/user/backup/differential/backup_diff"
bksource="/home/user/Documents"

destgen=`find $bkdest/* -exec md5sum {} + > diffmd5.txt`
sourcegen=`find $bksource/* -exec md5sum {} + > md5sum.txt`

    $sourcegen
    $destgen

$(cat diffmd5.txt) | while read f;
do
        if [ $(grep f md5sum.txt | wc -l) -lt 1 ]
            then
                # Code to backup the file that has changed or is not on record
                cp $(cut -d ' ' -f2-- <<< $f) $bkdest   
        fi
done
                # Afterwards, update md5hashes to list newly backed up files
                $sourcegen

请帮我找出我哪里出错了。谢谢!

猜猜这是我在 运行 处于调试模式时的错误

Try 'cp --help' for more information.
grep: md5sum.txt: No such file or directory
cut: invalid byte, character or field list
Try 'cut --help' for more information.
cp: missing destination file operand after ‘/home/dmitriy/backup/differential/backup_diff’

让我们试试:

#!/bin/bash

bkdest="/home/user/backup/differential/backup_diff"
bksource="/home/user/Documents"

cd $bkdest
find . -type f -exec md5sum {} \; > /tmp/md5dest.txt

cd $bksource
find . -type f -exec md5sum {} \; | while read c f; do
    if fgrep "$c" /tmp/md5dest.txt | fgrep -q "$f"; then
       echo "$f" ignored
    else
       cp $f $bkdest
    fi
done