#!/bin/bash # Script to backup postgres instance from docker db=kava user=odoo container=database now=$(date +%d-%m-%Y"_"%H-%M-%S) today=$(date +%d_%m_%Y) tmp_file=/opt/$db'_'$now.tar local_dir=/mnt/backup/local/ nfs_dir=/mnt/backup/nfs/ folder_name=backup_$today if [ ! -d $local_dir$folder_name ]; then mkdir $local_dir$folder_name fi docker exec $container pg_dump -U $user -d $db -F tar -C -b -c -f $tmp_file docker cp $container:$tmp_file $local_dir$folder_name docker exec $container rm $tmp_file if [ ! -d $nfs_dir$folder_name ]; then mkdir $nfs_dir$folder_name fi cp $local_dir$folder_name'/'$db'_'$now.tar $nfs_dir$folder_name