smart-backup.sh 646 B

1234567891011121314151617181920212223242526
  1. #!/bin/bash
  2. # Script to backup postgres instance from docker
  3. db=smart
  4. user=odoo
  5. container=database
  6. now=$(date +%d-%m-%Y"_"%H-%M-%S)
  7. today=$(date +%d_%m_%Y)
  8. tmp_file=/opt/$db'_'$now.tar
  9. local_dir=/mnt/backup/local/
  10. nfs_dir=/mnt/backup/nfs/
  11. folder_name=backup_$today
  12. if [ ! -d $local_dir$folder_name ]; then
  13. mkdir $local_dir$folder_name
  14. fi
  15. docker exec $container pg_dump -U $user -d $db -F tar -C -b -c -f $tmp_file
  16. docker cp $container:$tmp_file $local_dir$folder_name
  17. docker exec $container rm $tmp_file
  18. if [ ! -d $nfs_dir$folder_name ]; then
  19. mkdir $nfs_dir$folder_name
  20. fi
  21. cp $local_dir$folder_name'/'$db'_'$now.tar $nfs_dir$folder_name