github.com/cloudberrydb/gpbackup@v1.0.3-0.20240118031043-5410fd45eed6/plugins/example_plugin.bash (about) 1 #!/bin/bash 2 set -e 3 4 setup_plugin_for_backup(){ 5 echo "setup_plugin_for_backup $1 $2 $3 $4" >> /tmp/plugin_out.txt 6 if [[ "$3" = "coordinator" || "$3" = "master" ]] 7 then echo "setup_plugin_for_backup was called for scope = $3" >> /tmp/plugin_out.txt 8 elif [ "$3" = "segment_host" ] 9 then echo "setup_plugin_for_backup was called for scope = segment_host" >> /tmp/plugin_out.txt 10 elif [ "$3" = "segment" ] 11 then echo "setup_plugin_for_backup was called for scope = segment" >> /tmp/plugin_out.txt 12 fi 13 timestamp_dir=`basename "$2"` 14 timestamp_day_dir=${timestamp_dir%??????} 15 mkdir -p /tmp/plugin_dest/$timestamp_day_dir/$timestamp_dir 16 } 17 18 setup_plugin_for_restore(){ 19 echo "setup_plugin_for_restore $1 $2 $3 $4" >> /tmp/plugin_out.txt 20 if [[ "$3" = "coordinator" || "$3" = "master" ]] 21 then echo "setup_plugin_for_restore was called for scope = $3" >> /tmp/plugin_out.txt 22 elif [ "$3" = "segment_host" ] 23 then echo "setup_plugin_for_restore was called for scope = segment_host" >> /tmp/plugin_out.txt 24 elif [ "$3" = "segment" ] 25 then echo "setup_plugin_for_restore was called for scope = segment" >> /tmp/plugin_out.txt 26 fi 27 } 28 29 cleanup_plugin_for_backup(){ 30 echo "cleanup_plugin_for_backup $1 $2 $3 $4" >> /tmp/plugin_out.txt 31 if [[ "$3" = "coordinator" || "$3" = "master" ]] 32 then echo "cleanup_plugin_for_backup was called for scope = $3" >> /tmp/plugin_out.txt 33 elif [ "$3" = "segment_host" ] 34 then echo "cleanup_plugin_for_backup was called for scope = segment_host" >> /tmp/plugin_out.txt 35 elif [ "$3" = "segment" ] 36 then echo "cleanup_plugin_for_backup was called for scope = segment" >> /tmp/plugin_out.txt 37 fi 38 } 39 40 cleanup_plugin_for_restore(){ 41 echo "cleanup_plugin_for_restore $1 $2 $3 $4" >> /tmp/plugin_out.txt 42 if [[ "$3" = "coordinator" || "$3" = "master" ]] 43 then echo "cleanup_plugin_for_restore was called for scope = $3" >> /tmp/plugin_out.txt 44 elif [ "$3" = "segment_host" ] 45 then echo "cleanup_plugin_for_restore was called for scope = segment_host" >> /tmp/plugin_out.txt 46 elif [ "$3" = "segment" ] 47 then echo "cleanup_plugin_for_restore was called for scope = segment" >> /tmp/plugin_out.txt 48 fi 49 } 50 51 restore_file() { 52 echo "restore_file $1 $2" >> /tmp/plugin_out.txt 53 filename=`basename "$2"` 54 timestamp_dir=`basename $(dirname "$2")` 55 timestamp_day_dir=${timestamp_dir%??????} 56 cat /tmp/plugin_dest/$timestamp_day_dir/$timestamp_dir/$filename > $2 57 } 58 59 backup_file() { 60 echo "backup_file $1 $2" >> /tmp/plugin_out.txt 61 filename=`basename "$2"` 62 timestamp_dir=`basename $(dirname "$2")` 63 timestamp_day_dir=${timestamp_dir%??????} 64 cat $2 > /tmp/plugin_dest/$timestamp_day_dir/$timestamp_dir/$filename 65 } 66 67 backup_data() { 68 echo "backup_data $1 $2" >> /tmp/plugin_out.txt 69 filename=`basename "$2"` 70 timestamp_dir=`basename $(dirname "$2")` 71 timestamp_day_dir=${timestamp_dir%??????} 72 cat - > /tmp/plugin_dest/$timestamp_day_dir/$timestamp_dir/$filename 73 } 74 75 restore_data() { 76 echo "restore_data $1 $2" >> /tmp/plugin_out.txt 77 filename=`basename "$2"` 78 timestamp_dir=`basename $(dirname "$2")` 79 timestamp_day_dir=${timestamp_dir%??????} 80 cat /tmp/plugin_dest/$timestamp_day_dir/$timestamp_dir/$filename 81 } 82 83 delete_backup() { 84 echo "delete_backup $1 $2" >> /tmp/plugin_out.txt 85 timestamp_day_dir=${2%??????} 86 rm -rf /tmp/plugin_dest/$timestamp_day_dir/$2 87 if [ -z "$(ls -A /tmp/plugin_dest/$timestamp_day_dir/)" ] ; then 88 rm -rf /tmp/plugin_dest/$timestamp_day_dir 89 fi 90 91 } 92 93 plugin_api_version(){ 94 echo "0.4.0" 95 echo "0.4.0" >> /tmp/plugin_out.txt 96 } 97 98 --version(){ 99 echo "example_plugin version 1.1.0" 100 echo "example_plugin version 1.1.0" >> /tmp/plugin_out.txt 101 } 102 103 "$@"