Advertisement
jaimerosariojusticia

TGZ individual folder backup by date

Jul 28th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.56 KB | None | 0 0
  1. #!/bin/bash
  2. BACKUP_SRV="/mnt/tgz-backup/"
  3. EXCLUDE="/usr/share/exclude.list"
  4. CURRENTDAY=$(date +%F)
  5. CURRENTMONTH=$(date +%Y-%m)
  6. #
  7. find /mnt/UserData/ -maxdepth 1 -mindepth 1 -type d | while read -r d
  8. do DSTDIR=$BACKUP_SRV/UserData
  9. TARGZ=$(echo "$d" | cut -d "/" -f5)
  10. if [ -f "$DSTDIR"/"$TARGZ"_full.tgz ]
  11. then
  12.         mkdir "$DSTDIR"/"$CURRENTMONTH" > /dev/null 2>&1
  13.         tar -czf "$DSTDIR"/"$CURRENTMONTH"/"$TARGZ"_"$CURRENTDAY".tgz "$d" --newer-mtime '20 hours ago' -X $EXCLUDE
  14. else
  15.         tar -czf "$DSTDIR"/"$TARGZ"_full.tgz "$d" -X $EXCLUDE
  16. fi
  17. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement