New Backup Script


Primeiramente gostaria de salientar que não sou o autor principal do conteúdo deste artigo. A minha intenção é de mostrar o que outros autores tem realizado (referenciando links para o conteúdo original) neste blog até como um guia pessoal para uso próprio e ainda compartilhar minhas anotações e pequenas modificações que realizo no conteúdo, desejando que possa ajudar mais alguém em algum lugar.
First and foremost, I take no credit for any of this post’s content. I am really just taking what others have done (which I have links to bellow) and am putting it on my blog for a personal reference and hopefully the small changes that I made to their guides will help someone somewhere.

/usr/local/bin/backup.sh


#! /bin/bash
set -e

echo "backup key script running ..."
echo "see log at : /var/tmp/backup.log"
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3 RETURN
exec 1>/var/tmp/backup.log 2>&1

#Turn backup led on
echo 1 > /sys/class/leds/status:blue:backup_led/brightness

echo -n 180 > /sys/block/sda/device/timeout
echo -n 180 > /sys/block/sdb/device/timeout

source  /usr/local/bin/copy_all.sh

echo "Backup Kimax Pictures"
until rsync -avh --progress --delete /srv/media/Pictures/ rsync://192.168.1.14/media/Pictures 
do echo "Tentando novamente ...." 
done

echo "Backup Kimax Music"
until rsync -avh --progress --delete /srv/media/Music/ rsync://192.168.1.14/media/Music
do echo "Tentando novamente ...."
done

echo "Backup Kimax Movies"
until rsync -avh --progress --delete /srv/media/Movies/ rsync://192.168.1.14/media/Movies
do echo "Tentando novamente ...."
done



echo "Backup svnserver"
svnsync --non-interactive synchronize file:///srv/svn/edifast   || true

#echo "Backup Google Storage"
#echo y | bash /usr/local/share/vanaware/scripts/gs_download.sh all  || true


#Turn backup led off
echo 0 > /sys/class/leds/status:blue:backup_led/brightness

#return
exit 0



/usr/local/bin/copy_all.sh


#! /bin/bash

libsmount="/mnt/btrfs";
echo "Copying entire disk to mounted disk at ${libsmount} ..."

function intosubdir()
{
local depth="${1}"
local dir="${2}"
if [[ ! " ${partial[@]} " =~ " ${dir} " ]]; then
if [[ $dir == "/srv/media/Movies"* || $dir == "/srv/media/Pictures"* || $dir == "/srv/media/Music"* || $dir == "/srv/media/Users"* || $dir == "/srv/media/Documents"* ]]; then
echo "Media folder"
echo -n "Changing permissions : "
echo "chmod 777 ${dir}*"
chmod 777 "${dir}*" || true
echo -n "Changing owner : "
echo "chown root:users ${dir}"*
chown root:users "${dir}"* || true
fi
echo "rsync -dmpgoDAXh --exclude 'swapfile' ${dir} $libsmount${dir%%/}"
rsync -dmpgoDAXh --exclude 'swapfile' "${dir}" "$libsmount${dir%%/}"
for subdir in "${dir}"*/; do
if [[ ! " ${partial[@]} " =~ " ${subdir} " ]]; then
echo -n "Folder :  ${subdir}  ==>  "
case "${subdir%%/}" in
"${dir}*")
echo "skipping no subfolder ... "
;;
"/dev"|"/proc"|"/sys"|"/tmp"|"/run"|"/mnt"|"/media"|"/lost+found"|"/home")
echo "skipping ... "
;;
"/usr/local/share/vanaware")
echo "skipping ... "
;;
"/var/log"|"/var/cache"|"/var/tmp")
echo "skipping ... "
;;
"/srv/lost+found")
echo "skipping ... "
;;
"/srv/media/Documents/Backups"|"/srv/media/Documents/PDF"|"/srv/media/Documents/Server")
echo "skipping ... "
;;
"/srv/media/Users/Movies"|"/srv/media/Users/Pictures")
echo "skipping ... "
;;
"/srv/home/"[ia]"arvati/Documentos"|"/srv/home/"[ia]"arvati/Família"|"/srv/home/"[ia]"arvati/Imagens"|"/srv/home/"[ia]"arvati/Músicas"|"/srv/home/"[ia]"arvati/Vídeos"|"/srv/home/"[ia]"arvati/xxx")
echo "skipping ... "
;;
"/bin"|"/boot"|"/core"|"/etc"|"/lib"|"/opt"|"/root"|"/sbin"|"/usr")
echo "rsync -rlpgotDAXhK --delete ${subdir} $libsmount${subdir%%/}"
rsync -rlpgotDAXhK --delete "${subdir}" "$libsmount${subdir%%/}"
;;
*)
if [ $depth -le 1 ]
then
if [[ $subdir == "/srv/media/Movies"* || $subdir == "/srv/media/Pictures"* || $subdir == "/srv/media/Music"* || $subdir == "/srv/media/Users"* || $subdir == "/srv/media/Documents"* ]]; then
echo "Media folder"
echo -n "Changing permissions : "
echo "chmod 777 -R ${subdir%%/}"
chmod 777 -R "${subdir%%/}" || true
echo -n "Changing owner : "
echo "chown root:users -R ${subdir%%/}"
chown root:users -R "${subdir%%/}" || true
fi
echo "rsync -rlpgotDAXhK --delete ${subdir} $libsmount${subdir%%/}"
rsync -rlpgotDAXhK --delete "${subdir}" "$libsmount${subdir%%/}" || true
else
echo "going into depth $[$depth-1]"
intosubdir $[$depth-1] "${subdir}"
fi
;;
esac
echo ${subdir} >> /var/tmp/backup.partial
else
echo "Folder :  ${subdir} found at /var/tmp/backup.partial, skipping ..."
fi
done
else
echo "Folder :  ${dir} found at /var/tmp/backup.partial, skipping ..."
fi
}

# Mount predefined disk UUID
mount -t btrfs UUID=1da2f837-675c-41de-ac88-088bcab75199 "${libsmount}" || true
if mount | grep "on ${libsmount} type" > /dev/null
then
    echo "Backup Disk Mounted"
unset IFS
declare -a partial
if [ -f /var/tmp/backup.partial ]; then
echo "File partial found!"
readarray -t partial < /var/tmp/backup.partial
fi
intosubdir 5 "/"
if [ -f /var/tmp/backup.partial ]; then
echo "Removing partial file ..."
rm -f /var/tmp/backup.partial
fi

else
    echo "Backup Disk NOT Mounted"
fi

return
exit 0









O URL específico do gadget não foi encontrado



ċ
backup.sh
(1k)
Ademar Arvati Filho,
6 de abr de 2017 16:39
ċ
copy_all.sh
(4k)
Ademar Arvati Filho,
6 de abr de 2017 16:38
Comments