s4

view scripts/trans-user.sh @ 561:593e5ae3bd49

add trans-user.sh
author HIROSE Yuuji <yuuji@gentei.org>
date Sun, 14 Apr 2019 14:27:04 +0900
parents
children
line source
1 #!/bin/sh
3 while getopts r i; do
4 case $i in
5 r) mode=restore ;;
6 esac
7 done
8 shift $((OPTIND - 1))
10 if [ -z "$2" ]; then
11 cat<<-EOF >&2
12 Usage:
13 $0 DB out.csv user(s) - dump users to out.csv
14 $0 -r DB out.csv - import nonexistent user from out.csv
15 EOF
16 exit 1
17 fi
19 target=$(cd `dirname "$1"`; pwd)/`basename $1`
21 db=$1
22 shift
23 out=$1
24 shift
26 if [ x"$mode" = x"restore" ]; then
27 echo "begin;"
28 echo ".read $out"
29 echo "end;"
30 else
31 echo ".output $out"
32 for u; do
33 echo ".mode insert user"
34 echo "SELECT * FROM user WHERE name LIKE '$u';"
35 echo ".mode insert user_s"
36 echo "SELECT * FROM user_s WHERE name LIKE '$u';"
37 echo ".mode insert user_m"
38 echo "SELECT * FROM user_m WHERE name LIKE '$u';"
39 done
40 fi | sqlite3 $db