Qunhui photo video sorting and filing - end

#!/bin/bash
# Copy.sh : Backup the files to remote storage.
readonly pDir="${1:-~/XiaoMi/Image/}"  # Photo file backup path
readonly vDir="${2:-~/XiaoMi/Video/}"  # Video file backup path
readonly dDir="${3:-~/XiaoMi/Document/}" # Log storage directory
readonly iLog="${dDir}Copy.log"  # Backup success
readonly wLog="${dDir}Copy.wan"  # Already exist
readonly eLog="${dDir}Copy.err"  # No backup and error information required
readonly debug=false  # Commissioning switch, on demand
readonly stdName="(^|[[:space:]])[2,1][0,9][0,1,2,7,9][0-9][0-1][0-9][0-3][0-9]-[0-2][0-9][0-5][0-9][0-5][0-9]($|[[:space:]])" # standard format
find ~{higkoo,anglix}/Drive/{Moments,Backup} ! -path "*@eaDir*" -type f | while read -r sPath; do
    unset fName sExt rCopy rCode nDir dPath
    sExt="${sPath##*.}" && sExt="${sExt,,}"
    [[ ${sExt} == "jpeg" ]] && sExt='jpg'  # Change jpeg suffix to jpg
    fName="${sPath##*/}" && fName="${fName%%.*}"
    if [[ $fName =~ $stdName ]]; then  # Identify file name
        case $sExt in
            jpg | livp | heic | cr2 )
                nDir="${pDir}${fName:0:4}/"
                rCopy=true && rCode='+'
            ;;
            mp4 | mov | m4v | wmv )
                nDir="${vDir}${fName:0:4}/"
                rCopy=true && rCode='-'
            ;;
            png | * )  # Despise png, all screenshots
                rCopy=false && rCode='*'
            ;;
        esac
    else
        rCopy=false && rCode='/'
    fi

    if [[ $rCopy && ! -z ${nDir} ]]; then
        dPath="${nDir}${fName}.${sExt}"
        if [[ ! -f "${dPath}" || `stat --printf=%s "${dPath}" 2>/dev/null` -lt `stat --printf=%s "${sPath}"` ]]; then
            mkdir -pv "${nDir}" >>  ${wLog}
            cp -v "${sPath}" "${dPath}" >>${iLog} 2>>${eLog} 
        else
            echo "$sPath" >> ${wLog} && rCode='^'
        fi
    else
        echo "$sPath" >> ${eLog}
    fi
    echo -ne "$rCode"
    $debug && declare -p sPath dPath && exit 0
done
  • Photos are small in size and relatively easy to move and share, so they are independently opened with videos and are catalogued by year.
  • After a lot of hard work, the script starts to run for a while:
  • Previously, it was renamed with exiv2 and backed up once, so many ^.
  • +For a new photo, - for a new video, / is a file that does not need to be backed up.
  • At this point, the photo / video finishing work is finished, and the rest is to back them up safely (omitted).

Tags: SQLite REST

Posted on Sat, 07 Mar 2020 09:30:42 -0500 by mofm