Skip to content

Instantly share code, notes, and snippets.

@alkcxy
Created January 7, 2016 07:37
Show Gist options
  • Save alkcxy/12e491bf351b0125b954 to your computer and use it in GitHub Desktop.
Save alkcxy/12e491bf351b0125b954 to your computer and use it in GitHub Desktop.
This script copy files on a directory in a glacier vault without overriding existing ones. HOW TO bin/awsglacier.sh prova where prova is the directory to backup that is present inside $backup. You also need to create the dir $HOME/logs and $HOME/pids
#!/bin/bash
## change setting
# backup is the root directory of your directory to backup
# $1 is the subdirectory where are located the files to backup.
backup=/your/dir/backup
## end change setting
inizio=`date +%s`
mypidfile=$HOME/pids/aws.pid
backupdir="${backup}/$1"
vault="${1}_backup"
vaultfile="${backup}/${vault}.txt"
logfile="${HOME}/logs/${vault}.log"
bandwidth=80
timestart=100
timeend=500
if [ -f $mypidfile ]; then
echo "un programma amazon è già in esecuzione" >> $logfile
exit 1
fi
# Could add check for existence of mypidfile here if interlock is
# needed in the shell script itself.
# Ensure PID file is removed on program exit.
trap "rm -f -- '$mypidfile'" EXIT
# Create a file with current PID to indicate that process is running.
echo $$ > "$mypidfile"
echo "Comincia l'upload" >> $logfile
if [ ! -f $vaultfile ]; then
touch $vaultfile
fi
for i in `ls $backupdir`; do
date_now=`date +%_H%M`
if [ $date_now -lt $timestart ] || [ $date_now -gt $timeend ]; then
echo "Orario di interruzione attività"
echo "Orario di interruzione attività: la copia dei file non è completata, proseguirà al prossimo lancio schedulato" >> $logfile
fine=`date +%s`
echo "Operazione eseguita in $(($fine-$inizio)) secondi" >> $logfile
exit 0
fi
grep -Fxq "$i" ${vaultfile}
if [ $? -ne 0 ]; then
echo upload di: $i >> $logfile
#trickle -su $bandwidth
/usr/local/bin/aws glacier upload-archive --account-id - --vault-name $vault --body ${backupdir}/${i}
if [ $? -eq 0 ]; then
echo $i >> ${vaultfile}
else
echo "errore durante la copia di $i" >> $logfile
fi
#else
#echo "file $i già caricato" >> $logfile
fi
done
fine=`date +%s`
echo "Operazione eseguita in $(($fine-$inizio)) secondi" >> $logfile
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment