Rework backup script to be more versatile
This breaks the restore script but restoration from s3 should be easy enough now
This commit is contained in:
parent
b0235fb70f
commit
0f9f574bac
@ -46,6 +46,23 @@ if command -v ostree > /dev/null 2>&1; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Helper functions
|
||||||
|
backup() {
|
||||||
|
# Takes a file or directory to backup and backs it up
|
||||||
|
[ -z "$1" ] && return 1
|
||||||
|
|
||||||
|
dir="$1"
|
||||||
|
echo "- $dir"
|
||||||
|
|
||||||
|
nice -n 10 tar {{ backup_s3backup_tar_args }}{{ backup_s3backup_tar_args_extra }} \
|
||||||
|
{% for item in backup_s3backup_exclude_list + backup_s3backup_exclude_list_extra %}
|
||||||
|
--exclude "{{ item }}" \
|
||||||
|
{% endfor %}
|
||||||
|
"$dir" \
|
||||||
|
| aws s3 cp --expected-size 274877906944 - \
|
||||||
|
"s3://{{ backup_s3_bucket }}/{{ inventory_hostname }}/$dir/$(date "+{{ backup_dateformat }}").tar.gz"
|
||||||
|
}
|
||||||
|
|
||||||
# Tar up all items in the backup list, recursively, and pipe them straight
|
# Tar up all items in the backup list, recursively, and pipe them straight
|
||||||
# up to S3
|
# up to S3
|
||||||
if [ -n "${DIRS[*]}" ]; then
|
if [ -n "${DIRS[*]}" ]; then
|
||||||
@ -57,14 +74,16 @@ if [ -n "${DIRS[*]}" ]; then
|
|||||||
{% for item in backup_s3backup_exclude_list + backup_s3backup_exclude_list_extra %}
|
{% for item in backup_s3backup_exclude_list + backup_s3backup_exclude_list_extra %}
|
||||||
echo "- {{ item }}"
|
echo "- {{ item }}"
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
echo "Will upload resultant backup to {{ backup_s3_bucket }}"
|
echo "Will upload resultant backups to {{ backup_s3_bucket }}"
|
||||||
nice -n 10 tar {{ backup_s3backup_tar_args }}{{ backup_s3backup_tar_args_extra }} \
|
for dir in "${DIRS[@]}"; do
|
||||||
{% for item in backup_s3backup_exclude_list + backup_s3backup_exclude_list_extra %}
|
if [ "$dir" == "/data" ]; then
|
||||||
--exclude "{{ item }}" \
|
for datadir in "$dir"/*; do
|
||||||
{% endfor %}
|
[ -e "$datadir" ] && backup "$datadir"
|
||||||
"${DIRS[@]}" \
|
done
|
||||||
| aws s3 cp --expected-size 274877906944 - \
|
else
|
||||||
"s3://{{ backup_s3_bucket }}/{{ inventory_hostname }}/$(date "+{{ backup_dateformat }}").tar.gz"
|
backup "$dir"
|
||||||
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Dump Postgres DBs, if possible
|
# Dump Postgres DBs, if possible
|
||||||
@ -86,6 +105,6 @@ if command -v psql > /dev/null 2>&1; then
|
|||||||
sudo -u postgres pg_dump "$db" \
|
sudo -u postgres pg_dump "$db" \
|
||||||
| gzip -v9 \
|
| gzip -v9 \
|
||||||
| aws s3 cp - \
|
| aws s3 cp - \
|
||||||
"s3://{{ backup_s3_bucket }}/{{ inventory_hostname }}/$db-$(date "+{{ backup_dateformat }}").pgsql.gz"
|
"s3://{{ backup_s3_bucket }}/{{ inventory_hostname }}/pgdump/$db/$(date "+{{ backup_dateformat }}").pgsql.gz"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user