Last active
November 14, 2016 19:52
-
-
Save fabiomontefuscolo/1a136b0805d6a897935f562715843fb1 to your computer and use it in GitHub Desktop.
Small script to backup wordpress uploads. It creates a full tar in monday and incremental tars until the end of week.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
BACKUP_FOLDER='/srv/backups/uploads' | |
SOURCE_FOLDER='/var/www/awesomesite/wp-content/uploads' | |
PREFIX_NAME='awesomesite' | |
# ----------------------------------------------------- | |
woy=`date +%W` # muda toda segunda-feira | |
dow=`date +%w` # valor é 1 na segunda-feira | |
count=`find $BACKUP_FOLDER -maxdepth 1 -name "${PREFIX_NAME}.${woy}.*.tar" | wc -l` | |
control_name="${PREFIX_NAME}.${woy}.txt" | |
backup_name="${PREFIX_NAME}.${woy}.${count}.tar" | |
control_path="${BACKUP_FOLDER%%/}/$control_name" | |
backup_path="${BACKUP_FOLDER%%/}/$backup_name" | |
if [ -f "$backup_path" ]; | |
then | |
echo "Erro: '${backup_path}' já existe" | |
exit 1; | |
fi | |
tar -cf $backup_path --listed-incremental=$control_path $SOURCE_FOLDER | |
if [ "$dow" = "1" ]; | |
then | |
lwoy=$(( $woy-1 )) | |
control_name="${PREFIX_NAME}.${lwoy}.txt" | |
control_path="${BACKUP_FOLDER%%/}/$control_name" | |
rm -f $control_path | |
find $BACKUP_FOLDER -maxdepth 1 -name "${PREFIX_NAME}.${lwoy}.*.tar" -delete | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment