Advertisement
OwniiEU

Bash - Backuper

Nov 25th, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.76 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ## If direcotry '_Backup' doesnt exists, create it
  4. if test ! -d "_Backup"
  5. then
  6.     mkdir _Backup
  7.     echo "Das Verzeichnis '_Backup' existierte noch nicht und wurde erstellt"
  8. fi
  9.  
  10. for f in $(ls)
  11. do
  12.     ## File is no directory
  13.     if test ! -d "$f"
  14.     then
  15.         ## Should file copy or not
  16.         read -p "Soll die Datei '$f' kopiert werden? [y|n]" yn
  17.         case $yn in
  18.             [Yy] )
  19.            
  20.                 ## Append _cp if file already exists in '_Backup'
  21.                 newfile=$f
  22.                 if test -e "_Backup/$f"
  23.                 then
  24.                     newfile=$newfile"_cp"
  25.                     echo "'$f' existiert bereits im Verzeichnis '_Backup' -> wird kopiert als '$newfile'"
  26.                 fi
  27.                
  28.                 ## Copy file
  29.                 cp $f "_Backup/$newfile"
  30.                 echo "Datei '$f' wurde kopiert"
  31.             ;;
  32.             * ) echo "skipping file '$f'";;
  33.         esac
  34.     fi
  35. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement