From cc21b2d23bf0008a9b5cba542a430c7a0b414ac1 Mon Sep 17 00:00:00 2001 From: zhaominyong Date: Fri, 5 Aug 2022 16:59:00 +0800 Subject: [PATCH] =?UTF-8?q?132570=20=E3=80=90=E5=A4=87=E4=BB=BD=E8=BF=98?= =?UTF-8?q?=E5=8E=9F=E3=80=91=E5=9C=A8=E5=A4=87=E4=BB=BD=E8=BF=98=E5=8E=9F?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E4=B8=AD=E6=9F=A5=E7=9C=8B=E5=88=B0=E5=87=BA?= =?UTF-8?q?=E5=9C=BA=E5=A4=87=E4=BB=BD=E6=9C=8917G=EF=BC=8C=E4=BD=86df=20-?= =?UTF-8?q?h=E6=9F=A5=E7=9C=8Bbackup=E5=8F=AA=E4=BD=BF=E7=94=A8=E4=BA=869G?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup-daemon/data/backup-auto | 38 +++++++++++++++++++++++++----- backup-daemon/data/backup-auto-efi | 2 +- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/backup-daemon/data/backup-auto b/backup-daemon/data/backup-auto index 1157b5d..b68c0dd 100755 --- a/backup-daemon/data/backup-auto +++ b/backup-daemon/data/backup-auto @@ -33,6 +33,8 @@ fi m_backuplistPath=${m_mountPath}${BACKUP}"/snapshots/backuplist.xml" EXCLUDEFILE=${m_mountPath}${BACKUP}"/snapshots/.exclude" +PLOGFILEDIR="${m_mountPath}${BACKUP}/log" +PLOGFILE="$PLOGFILEDIR/log-$(date +%Y%m%d%H%M)" LOGFILE="/backup"${BACKUP}"/log.txt" #LOGFILE="/tmp/log.txt" #是否是出厂备份 @@ -121,6 +123,19 @@ mountBackup() mount $myuuid $m_mountPath + mkdir -p $PLOGFILEDIR + if [ $? -ne 0 ]; then + echo "Could not create log directory in /backup" + exit 22 + fi + + touch $PLOGFILE + if [ $? -ne 0 ]; then + echo "Could not create log file" + exit 23 + fi + echo "Log for backuping and restoring...." >$PLOGFILE + createBackupList #创建备份信息 } @@ -208,6 +223,14 @@ is_remote(){ fi } +function caculateDirSize() { + mkdir -p /backup/snapshots/check/data + local total_file_size=$(rsync -aAHXrn --stats --ignore-missing-args --exclude=/backup --exclude=/cdrom --exclude=/dev --exclude=/efi --exclude=/etc/uid_list --exclude=/data/ghost --exclude=/ghost --exclude=/lost+found --exclude=/media --exclude=/mnt --exclude=/proc --exclude=/run --exclude=/swap_file --exclude=/sys --exclude=/tmp --exclude=/var/lib/docker/overlay2 --exclude=/var/lib/kmre/data --exclude=/var/lib/kmre/kmre-*-*/data/media/0/0-麒麟* --exclude=/var/lib/udisks2 --exclude=/var/log --exclude=*/backup/snapshots --exclude=/data/home --exclude=/data/root "${rootpath}/" /backup/snapshots/check/data/ | grep "Total file size:" | awk '{print $4}' | sed 's/,//g') + total_file_size=$(expr ${total_file_size} + 200000000) + echo "备份所需空间大小:${total_file_size}" >>$PLOGFILE + echo "${total_file_size}" +} + #parameters: 无 #返回值:(system_totalSize system_freeDisk system_usedDisk) caculateSystemSize(){ @@ -257,7 +280,8 @@ caculateSystemSize(){ continue fi - #echo $line + echo $line + echo $line >>$PLOGFILE device=$( echo "$line"|awk '{print $1}') mntdir=$( echo "$line"|awk '{print $2}') @@ -363,7 +387,8 @@ checkBackupCapacity() { #(m_rootPath.toStdString().c_str(), retstatus)) system_freeDisk=${result[1]} system_usedDisk=${result[2]} - global_system_usedDisk=$system_usedDisk + #global_system_usedDisk=$system_usedDisk + global_system_usedDisk=$(caculateDirSize) #echo "--system_totalSize="$system_totalSize #echo "--system_freeDisk="$system_freeDisk @@ -403,10 +428,11 @@ checkBackupCapacity() { #(m_rootPath.toStdString().c_str(), retstatus)) exit 403 fi - echo "bybobbi: bakup_freeDisk is " $backup_freeDisk - echo "bybobbi: system_usedDisk is " $system_usedDisk - - if [ "$backup_freeDisk" -gt "$system_usedDisk" ]; then + #echo "bybobbi: bakup_freeDisk is " $backup_freeDisk + #echo "bybobbi: system_usedDisk is " $system_usedDisk + echo "free size : $backup_freeDisk; sys_size : $global_system_usedDisk" + echo "free size : $backup_freeDisk; sys_size : $global_system_usedDisk" >>$PLOGFILE + if [ ${backup_freeDisk} -gt ${global_system_usedDisk} ]; then return 1 else return 0 diff --git a/backup-daemon/data/backup-auto-efi b/backup-daemon/data/backup-auto-efi index f044612..196e11b 100755 --- a/backup-daemon/data/backup-auto-efi +++ b/backup-daemon/data/backup-auto-efi @@ -250,7 +250,7 @@ is_remote() { function caculateDirSize() { mkdir -p /backup/snapshots/check/data - local total_file_size=$(rsync -aAHXrn --stats --ignore-missing-args --exclude=/backup --exclude=/cdrom --exclude=/dev --exclude=/efi --exclude=/etc/uid_list --exclude=/data/ghost --exclude=/ghost --exclude=/lost+found --exclude=/media --exclude=/mnt --exclude=/proc --exclude=/run --exclude=/swap_file --exclude=/sys --exclude=/tmp --exclude=/var/lib/docker/overlay2 --exclude=/var/lib/kmre/data --exclude=/var/lib/kmre/kmre-*-*/data/media/0/0-麒麟* --exclude=/var/lib/udisks2 --exclude=/var/log --exclude=*/backup/snapshots --exclude=/data/home --exclude=/data/root --exclude=/home/zhaominyong/.box --exclude=/data/home/zhaominyong/.box --exclude=/data "${rootpath}/" /backup/snapshots/check/data/ | grep "Total file size:" | awk '{print $4}' | sed 's/,//g') + local total_file_size=$(rsync -aAHXrn --stats --ignore-missing-args --exclude=/backup --exclude=/cdrom --exclude=/dev --exclude=/efi --exclude=/etc/uid_list --exclude=/data/ghost --exclude=/ghost --exclude=/lost+found --exclude=/media --exclude=/mnt --exclude=/proc --exclude=/run --exclude=/swap_file --exclude=/sys --exclude=/tmp --exclude=/var/lib/docker/overlay2 --exclude=/var/lib/kmre/data --exclude=/var/lib/kmre/kmre-*-*/data/media/0/0-麒麟* --exclude=/var/lib/udisks2 --exclude=/var/log --exclude=*/backup/snapshots --exclude=/data/home --exclude=/data/root "${rootpath}/" /backup/snapshots/check/data/ | grep "Total file size:" | awk '{print $4}' | sed 's/,//g') total_file_size=$(expr ${total_file_size} + 200000000) echo "备份所需空间大小:${total_file_size}" >>$PLOGFILE echo "${total_file_size}"