123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- #!/bin/bash
- # {{ ansible_managed }}
- LOG_FILE="/var/log/rclone/rclone-$(date +%Y-%m-%d).log"
- {% if backups is defined and 'containers' in backups %}
- {% if containers is defined %}
- {% for container in containers %}
- {% if container.volumes is defined %}
- {% for volume in container.volumes %}
- {% if volume|regex_replace(':.*') not in backups_ignore %}
- echo "Starting backup of '{{ container.name }}:{{ volume | regex_replace(':.*') }}'." | ts >> "$LOG_FILE"
- /usr/bin/rclone copy {{ volume | regex_replace(':.*') }}/ b2-container-data:current/{{ ansible_hostname }}/{{ container.name }}/{{ volume | regex_replace(':.*') | basename }} \
- --backup-dir=b2-container-data:old/{{ ansible_hostname }}/{{ container.name }}/{{ volume | regex_replace(':.*') | basename }} \
- --suffix=-$(date +%Y-%m-%d) \
- --fast-list \
- --suffix-keep-extension \
- --exclude "*log" \
- --log-file="$LOG_FILE" -v
- if [[ $? > 0 ]]; then
- curl \
- -H "Title: rclone backup error" \
- -H "Priority: urgent" \
- -H "Tags: warning" \
- -d "Backup of {{ container.name }}:{{ volume | regex_replace(':.*') }} on $(hostname) had an error. Please check logs at $LOG_FILE" \
- https://ntfy.warchildstory.com/{{ ntfy_server_notifications }}
- fi
- echo "Finished backup of '{{ container.name }}:{{ volume | regex_replace(':.*') }}'." | ts >> "$LOG_FILE"
- {% endif %}
- {% endfor %}
- {% endif %}
- {% endfor %}
- {% endif %}
- {% endif %}
- {% if ansible_hostname == 'tvheadend' %}
- ## Photos
- PHOTOS_LOG="/tmp/b2-photos.log"
- > $PHOTOS_LOG
- echo "Starting backup of photos..." | ts >> "$LOG_FILE"
- #/usr/bin/rclone copy /mnt/nas/private/Photos b2-photos:current --backup-dir=b2-photos:old --suffix=-$(date +%Y-%m-%d) --fast-list --suffix-keep-extension --exclude "*DS_Store" --log-file=$PHOTOS_LOG | ts | tee -a "$LOG_FILE"
- /usr/bin/rclone copy /mnt/nas/private/Photos b2-photos:current --fast-list --immutable --exclude "*DS_Store" --log-file=$PHOTOS_LOG -v | ts | tee -a "$LOG_FILE"
- if [[ $? > 0 ]]; then
- curl \
- -H "Title: rclone backup error" \
- -H "Priority: urgent" \
- -H "Tags: warning" \
- -d "Backup of Photos on $(hostname) had an error. Please check logs at $LOG_DIR/$(basename -- $PHOTOS_LOG)" \
- https://ntfy.warchildstory.com/{{ ntfy_server_notifications }}
- fi
- mv "$PHOTOS_LOG" "$LOG_DIR"
- echo "Finished backing up photos" | ts >> "$LOG_FILE"
- # Data
- DATA_LOG="/tmp/b2-data.log"
- > $DATA_LOG
- echo "Starting backup of data..." | ts >> "$LOG_FILE"
- /usr/bin/rclone copy /mnt/nas/private/Data b2-data:current --backup-dir=b2-data:old --suffix=-$(date +%Y-%m-%d) --fast-list --suffix-keep-extension --exclude "*DS_Store" --log-file=$DATA_LOG -v | ts | tee -a "$LOG_FILE"
- if [[ $? > 0 ]]; then
- curl \
- -H "Title: rclone backup error" \
- -H "Priority: urgent" \
- -H "Tags: warning" \
- -d "Backup of Data on $(hostname) had an error. Please check logs at $LOG_DIR/$(basename -- $DATA_LOG)" \
- https://ntfy.warchildstory.com/{{ ntfy_server_notifications }}
- fi
- mv "$DATA_LOG" "$LOG_DIR"
- echo "Finished backing up data" | ts >> "$LOG_FILE"
- # Music
- MUSIC_LOG="/tmp/b2-music.log"
- > $MUSIC_LOG
- echo "Starting backup of music..." | ts >> "$LOG_FILE"
- /usr/bin/rclone copy /mnt/nas/public b2-music:current --backup-dir=b2-music:old --suffix=-$(date +%Y-%m-%d) --fast-list --suffix-keep-extension --include=Music/** --include="Music Videos"/** --log-file=$MUSIC_LOG -v | ts | tee -a "$LOG_FILE"
- if [[ $? > 0 ]]; then
- curl \
- -H "Title: rclone backup error" \
- -H "Priority: urgent" \
- -H "Tags: warning" \
- -d "Backup of Music on $(hostname) had an error. Please check logs at $LOG_DIR/$(basename -- $MUSIC_LOG)" \
- https://ntfy.warchildstory.com/{{ ntfy_server_notifications }}
- fi
- mv "$MUSIC_LOG" "$LOG_DIR"
- echo "Finished backing up music" | ts >> "$LOG_FILE"
- # Recipes
- RECIPES_LOG="/tmp/b2-recipes.log"
- > $RECIPES_LOG
- echo "Starting backup of recipes..." | ts >> "$LOG_FILE"
- /usr/bin/rclone copy /mnt/nas/public b2-data:current --backup-dir=b2-data:old --suffix=-$(date +%Y-%m-%d) --fast-list --suffix-keep-extension --include=Recipes/** --log-file=$RECIPES_LOG -v | ts | tee -a "$LOG_FILE"
- if [[ $? > 0 ]]; then
- curl \
- -H "Title: rclone backup error" \
- -H "Priority: urgent" \
- -H "Tags: warning" \
- -d "Backup of Recipes on $(hostname) had an error. Please check logs at $LOG_DIR/$(basename -- $RECIPES_LOG)" \
- https://ntfy.warchildstory.com/{{ ntfy_server_notifications }}
- fi
- mv "$RECIPES_LOG" "$LOG_DIR"
- echo "Finished backing up recipes" | ts >> "$LOG_FILE"
- {% endif %}
|