91 lines
1.8 KiB
Bash
91 lines
1.8 KiB
Bash
|
#!/bin/bash
|
||
|
BACKUP=false
|
||
|
UPDATE=false
|
||
|
help="Autor: Mariusz Aleszko
|
||
|
Grupa: 1CC
|
||
|
-a [opcja] Dodanie pliku do listy, ktorego ma byc robiona kopia
|
||
|
-r [opcja] Usuniecie pliku z listy, ktory nie ma byc juz backupowany
|
||
|
-b [opcja] Wykonanie backupu, po '-b' nalezy podac gdzie ma byc robiony backup(np. s439371@lts.wmi.amu.edu.pl)
|
||
|
-u Uzycie z opcja '-b'(np. ./backup.sh -b [xxxx] -u | backup nowych lub zmodyfikowanych plikow z listy
|
||
|
-h Pomoc"
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
if [ ! -e ~/.backup.lst ];
|
||
|
then
|
||
|
touch ~/.backup.lst
|
||
|
fi
|
||
|
|
||
|
function backup {
|
||
|
LIST=$(readlink -m ~/.backup.lst)
|
||
|
DATE=$(date +%Y-%m-%d-%H-%M-%S)
|
||
|
if [ -s $LIST ]; then
|
||
|
if [ $UPDATE != true ]; then
|
||
|
rsync -a / --files-from="$LIST" "$BACKUP_TARG:~/$DATE"
|
||
|
|
||
|
else
|
||
|
if [ -e ~/.lstbackup.lst ]; then
|
||
|
LASTBACKUP="$(cat ~/.lstbackup.lst)"
|
||
|
|
||
|
rsync -au / --files-from="$LIST" --compare-dest="../$LASTBACKUP" "$BACKUP_TARG:~/$DATE"
|
||
|
|
||
|
else
|
||
|
rsync -a / --files-from="$LIST" "$BACKUP_TARG:~/$DATE"
|
||
|
|
||
|
fi
|
||
|
fi
|
||
|
echo $DATE > ~/.lstbackup.lst
|
||
|
else
|
||
|
echo "Plik ze sciezkami nie istnieje lub jest pusty"
|
||
|
fi
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
while getopts :a:r:b:uh OPT;
|
||
|
do
|
||
|
case $OPT in
|
||
|
a)if [ $(grep -cx $(readlink -m $OPTARG) ~/.backup.lst) = 0 ]; then
|
||
|
readlink -e $OPTARG >> ~/.backup.lst
|
||
|
if [ ! -e $(readlink -m $OPTARG) ];then
|
||
|
echo "Plik $OPTARG nie istnieje"
|
||
|
fi
|
||
|
fi
|
||
|
;;
|
||
|
r)if [ $(grep -cx $(readlink -m $OPTARG) ~/.backup.lst) != 0 ]; then
|
||
|
REMOVE=$(grep -n "$(readlink -m $OPTARG)" ~/.backup.lst | grep -Eo '^[^:]+')
|
||
|
sed -i ${REMOVE}d ~/.backup.lst
|
||
|
fi
|
||
|
if [ ! -s ~/.backup.lst ];then
|
||
|
rm ~/.backup.lst
|
||
|
fi
|
||
|
;;
|
||
|
b) BACKUP=true
|
||
|
BACKUP_TARG=$OPTARG
|
||
|
|
||
|
;;
|
||
|
u)UPDATE=true
|
||
|
|
||
|
;;
|
||
|
h) echo "$help"
|
||
|
;;
|
||
|
\?) echo "Bledna opcja: -$OPTARG" >&2
|
||
|
exit 1
|
||
|
;;
|
||
|
:)echo "Opcja -$OPTARG wymaga argumentu" >&2
|
||
|
exit 1
|
||
|
;;
|
||
|
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
if [ $BACKUP = true ]; then
|
||
|
backup
|
||
|
fi
|
||
|
|
||
|
|