Skip to content

Commit

Permalink
shell script to backup/restore/delete custom dict
Browse files Browse the repository at this point in the history
  • Loading branch information
amutu committed Feb 9, 2024
1 parent b9d408d commit 60909b5
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions zhparser-backup-custom-dict.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
if [ $# -lt 2 ];then
echo "usage: $0 <backup|restore|delete> <pgdata_dir> [restore_from_dir]"
echo "warning: delete is a dangerous cmd, it will delete your custom from pgdata_dir."
echo "!!!you should run backup cmd first, then run the delete cmd !!!"
exit 2
fi
cmd=$1
pgdata=$2
restore_from_dir=$3

if [ $cmd = 'backup' ];then
backup_dir=zhparser-backup-custom-dict-$(date +'%F:%T')
mkdir ./$backup_dir
echo "will backup $pgdata/base/zhprs_dict_* to $backup_dir/"
cp -a $pgdata/base/zhprs_dict_* $backup_dir/
if [ "$?" -ne 0 ];
then
echo "backup error!"
exit 1
else
echo "backup ok!"
fi
fi

if [ $cmd = 'delete' ];then
echo "will delete $pgdata/base/zhprs_dict_*"
rm $pgdata/base/zhprs_dict_*
if [ "$?" -ne 0 ];
then
echo "delete error!"
exit 1
else
echo "delete ok!"
fi
fi

if [ $cmd = 'restore' ];then
echo "will restore $restore_from_dir/zhprs_dict_* to $pgdata/base/"
cp -a $restore_from_dir/zhprs_dict_* $pgdata/base/
if [ "$?" -ne 0 ];
then
echo "restore error!"
exit 1
else
echo "restore ok!"
fi
fi

0 comments on commit 60909b5

Please sign in to comment.