david/scripts-archive
david
/
scripts-archive
Archived
1
0
Fork 0
This repository has been archived on 2022-04-16. You can view files and clone it, but cannot push or open issues or pull requests.
scripts-archive/clonebackup/filebackup.sh

99 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
# # # # # # # # # # # # # # # #
# #
# DeepSpace File Backup #
# v0.1 #
# david@socialnerds.org #
# #
# # # # # # # # # # # # # # # #
## README SECTION
##
## nothing to read yet :-)
##
##
# definitions
configfile="/srv/scripts/filebackup.conf" # use absolut path
mountpath="/mnt"
backuppath="/srv/filebackup"
# gen timestamp
timestamp=$(echo $(date "+%d_%m_%C%y"))
# am i root
if [ "$(whoami)" != "root" ]; then
echo "error: only root can do this"
exit 1;
fi
# starting message with timestamp
echo
echo "info: starting deepspace filebackup on $timestamp"
echo
# check if configfile is there and readable
if [ -r $configfile ]; then
# read configfile
i=1
while read line; do
# check if first letter is a #
fletter=${line:0:1}
if [ -z "$line" ]; then
:
#echo "line $i is empty"
else
if [ $fletter == "#" ]; then
:
#echo "line $i a comment"
else
if [[ $line != *"@"*":"*";"* ]]; then
echo "error: line $i is not correct formated"
else
echo "info: reading config (line $i)"
userindex=`expr index "$line" @`
let userindex--
user=${line:0:$userindex}
#echo "user: $user"
hostindex=`expr index "$line" :`
let hostindex--
let userindex++
host=${line:$userindex:$(($hostindex-$userindex))}
#echo "host: $host"
passindex=`expr index "$line" ";"`
share=${line:$(($hostindex+1)):$(($passindex-$hostindex-2))}
#echo "share: $share"
pass=${line:$passindex}
#echo "password: $pass"
# check for mountpoint
if [ -d $mountpath/$i ]; then
echo "info: $mountpath/$i already exists"
else
mkdir -p $mountpath/$i
fi
echo "info: mounting $host$share to $mountpath/$i"
mount -t cifs -o username=$user,password=$pass //$host$share $mountpath/$i
# do backup
echo "info: creating destination folders"
mkdir -p $backuppath/$timestamp/$host$share/
echo "info: starting rsync job"
rsync -r $mountpath/$i/* $backuppath/$timestamp/$host$share/
# unmounting share
echo "info: unmounting $host$share"
umount $mountpath/$i
echo "info: backup done, please check if it's really there"
echo
fi
fi
fi
let i++
done < $configfile
else
echo "error: no configfile found"
exit 1
fi
exit 0