redashmanã使ã£ã¦Redashã®ã¯ã¨ãªããæ軽ã«ããã¯ã¢ãããã
ä»æ¥ã¯Redash Advent Calendar 16æ¥ç®ã§ããããã®è¨äºã¯Advent Calendarã®è¨äºã§ã¯ããã¾ããã
12/16ã®è¨äºã¯vankobeããã«ãããRedashã®çµæãGoogleã¹ãã¬ããã·ã¼ãã§æ±ãäºä¾ã®è¨äºã§ãã
Redashã®ä¾¿å©ãã¨ããã®è£ã«ããã¤ãã¿
Redashãæ´»ç¨ãã¯ããã¦1å¹´åã»ã©çµã¡ã¾ãããä»ã§ã¯Redashãªãã§æ¥åãåããªããªãã»ã©ã«ä½¿ãåãã¦ãã¾ãã
ããããRedashã®æ´»ç¨ãé²ãã ãã¨ã«ãã£ã¦ãRedashãè½ã¡ããå ¨ã¦ãæ¢ã¾ããã¨ãã£ãç¶æ³ã«ãªãã¤ã¤ãããã¨ãäºå®ã§ããã¾ã«Redashã®å容ãµã¼ãã¼ããã¢ã©ã¼ããé£ãã§ããã¨ãèçãåãæãããã¦ãã¾ãã
ããã ãã§ãªããRedashã®å©ç¹ã§ãããã誰ã§ãã¯ã¨ãªãå®è¡ã»ç·¨éã§ãããã¨ããã®ããéç¨ä¸åé¡ã«ãªããã¨ãä½åº¦ãçµé¨ãã¦ãã¾ããã
ãã®è¨äºã§ã¯Redashã®ã¯ã¨ãªã®ããã¯ã¢ããã«ã¤ãã¦ãèªä½ã®ãã¼ã« redashman
ã®å®£ä¼ããã¤ã¤ç´¹ä»ãã¦ããã¾ãã
Redashã®ããã¯ã¢ãã
ãã£ããã§ãããããæãã¤ãããã¯ã¢ããæ¹æ³ã¯ä»¥ä¸ã®2ã¤ã¨èãã¦ãã¾ãã
- Redashã¤ã³ã¹ã¿ã³ã¹ã®ãã£ã¹ã¯ã¤ã¡ã¼ã¸ã®ã¹ãããã·ã§ãããåå¾ãã
- Redashã®ç®¡çDB(PostgreSQL)ã®DBããã¯ã¢ãããåå¾ãã
æ§æã«ãããã¾ããããã£ã¹ã¯ã¤ã¡ã¼ã¸ã®ããã¯ã¢ããã¯IaaSã使ã£ã¦ããã°ããã£ã¨ãç°¡åãã¤å®å¿ã§ããæ¹æ³ãã¨æãã¾ãã
管çDBã®ããã¯ã¢ããã¯ãããã¯ã¢ããã¹ã¯ãªãããä¿åå ãç¨æããå¿ è¦ãããã¾ãããPostgreSQLã«ã¤ãã¦å°ãç¥èãããã°ç°¡åã«å®ç¾ã§ããæ¹æ³ã¨è¨ãã¾ãã
ä¸è¨ã®ããã«ããã£ã¹ã¯ããã¼ã¿ãã¼ã¹ã®åä½ã§ããã¯ã¢ãããã¨ã£ã¦ãããã¨ã¯éç¨ä¸éè¦ãªãã¨ã§ããããã¯ã¨ãªãã®ããã¯ã¢ããã«ã¤ãã¦ãèãã¦ã¿ã¾ãã
Redashã¯èª°ã§ãæ°è»½ã«ã¯ã¨ãªãå®è¡ã»ç·¨éãããã¨ãã§ããä¸æ¹ã§ãæªæã®æç¡ã«é¢ãããã誤ã£ã¦ã¯ã¨ãªãç·¨éãã¦ãã¾ããã¯ã¨ãªãå®è¡ã§ããªããªã£ã¦ãã¾ããã¨ãèãããã¾ãã
ããããå ã«ç´¹ä»ãããã£ã¹ã¯ããã¼ã¿ãã¼ã¹ã«ããããã¯ã¢ããã¯ãã¯ã¨ãªãã®ããã¯ã¢ããã¨ããç¹ã§èããã¨ãªã¹ãã¢ã®æéããããå°ã大ããã«æããé¨åãããã¾ãã
redashman
ã«ã¤ãã¦
ç¾å¨ãç§ã¯ redashman
ã¨ããèªä½ã®ãã¼ã«ãç¨ãã¦ãRedashã®ã¯ã¨ãªãå®æçã«ããã¯ã¢ãããã¦ãã¾ãã
Redashã管çããã®ã§ redashman
ã¨ããååã«ãã¾ãããããªããéããããããéã«å½ãã£ã¦ãã£ã¦ã³ãã£ã¦ã³ããå
æ¯ãç®ã«æµ®ããã ããã¯åå¥ã«ãé£çµ¡ãã ãããç§ã¯X4ã好ãã§ãã
ãã®ãã¼ã«ã¯ã¯ã¨ãªã®ä¸è¦§ãåå¾ãä½æãªã©ãCLIããå®è¡ããããã®ãã¼ã«ã¨ãã¦ä½æãã¾ãããããã®ä¸ã«ã¯ã¨ãªã®å®ç¾©ãåå¾ãããã®ãããã®ã§ãããã使ã£ã¦ã¯ã¨ãªãããã¯ã¢ãããã¦ãã¾ãã
ã¤ã³ã¹ãã¼ã«
redashman
ã¯Goã§æ¸ããã®ã§ãgo get
ã§ç°¡åã«ã¤ã³ã¹ãã¼ã«ã§ãã¾ãã
$ go get -u github.com/ariarijp/redashman
redashman
ã使ç¨ããã¯ã¨ãªã®ãæ軽ããã¯ã¢ãã
redashman
èªä½ã®ä½¿ãæ¹ã«ã¤ãã¦ã¯READMEãåç
§ãã¦ããã ãã¨ãã¦ãä»å±ã®Pythonã¹ã¯ãªããã使ç¨ãã¦ããã¯ã¢ããããã¦ã¿ã¾ãã
$ mkdir redash_backup $ cd redash_backup $ cp $GOPATH/src/github.com/ariarijp/redashman/scripts/backup_queries.py ./ $ export REDASH_URL=http://localhost $ export REDASH_API_KEY="Redashã®admin権éãããã¦ã¼ã¶ã¼ã®APIãã¼" $ python ./backup_queries.py $ ls -la backup total 48 drwxr-xr-x 8 ariarijp wheel 272 12 16 14:34 . drwxr-xr-x 4 ariarijp wheel 136 12 16 14:34 .. -rw-r--r-- 1 ariarijp wheel 23 12 16 14:34 0001.sql -rw-r--r-- 1 ariarijp wheel 51 12 16 14:34 0002.sql -rw-r--r-- 1 ariarijp wheel 89 12 16 14:34 0003.sql -rw-r--r-- 1 ariarijp wheel 83 12 16 14:34 0004.sql -rw-r--r-- 1 ariarijp wheel 89 12 16 14:34 0005.sql $ cat backup/0001.sql SELECT * FROM country;
ããã§ã¯ã¨ãªã®ããã¯ã¢ãããåå¾ãããã¨ãã§ããããã«ãªãã¾ããã
å®æçã«ããã¯ã¢ããããå¤æ´å±¥æ´ãæ®ã
å®æçã«ããã¯ã¢ãããããã«ã¯ãããä¸æéãããå¿ è¦ãããã¾ãã
ãã®ããã«ã以ä¸ã®ã¹ã¯ãªããã backup.sh
ã¨ãã¦ä¿åããå®è¡æ¨©éãä¸ãã¦ããã¾ãã
#!/bin/bash export REDASH_URL=http://localhost export REDASH_API_KEY="Redashã®admin権éãããã¦ã¼ã¶ã¼ã®APIãã¼" cd `dirname $0` if [ ! -d '.git' ]; then git init fi python backup_queries.py git add . && git ci -a -m `date '+%Y%m%d%H%M%S'`
ãããå®è¡ããã¨ãå ã»ã©ã®Pythonã¹ã¯ãªããã§ã¯ã¨ãªã®ããã¯ã¢ãããåå¾ãããã®ãã¡ã¤ã«ãGitãªãã¸ããªã«ã³ãããããã¾ãã
$ ./backup.sh Initialized empty Git repository in /private/tmp/redash_backup/.git/ [master (root-commit) 820ae32] 20171216144840 8 files changed, 49 insertions(+) create mode 100755 backup.sh create mode 100644 backup/0001.sql create mode 100644 backup/0002.sql create mode 100644 backup/0003.sql create mode 100644 backup/0004.sql create mode 100644 backup/0005.sql create mode 100644 backup_queries.py
ãã®ã¹ã¯ãªããã cron
ãªã©ã使ã£ã¦é©å½ãªééã§å®æå®è¡ããã°ãã¯ã¨ãªã®ããã¯ã¢ãããå®æçã«ããã¤ãGitã使ç¨ãããã¨ã§å±¥æ´ã¨ã¿ã¤ã ã¹ã¿ã³ãä»ãã§ä¿åãããã¨ãã§ããããã«ãªãã¾ãã
ã¾ã¨ã
Redashã®æ°è»½ããç¶æãã¤ã¤ãredashman
ã§ã¯ã¨ãªãå®æçã«ããã¯ã¢ãããããã¨ã§ãã¯ã¨ãªã誤ã£ã¦ç·¨éãã¦ãã¾ã£ããªã©ã®ãã©ãã«ã«å¯¾å¦ã§ããããã«ãªããå¯ç£ç©ã¨ãã¦ã¯ã¨ãªã®ç·¨éå±¥æ´ãGitã¨ããå¤ãã®éçºè
ã®æã«é¦´æãã ãã¼ã«ã§ç®¡çã§ããããã«ãªãã¾ãã
Redashã®å©ç¨ãããããæ¤è¨ãã¦ããæ¹ã«ãããã² redashman
ã®å°å
¥ãæ¤è¨ãã¦ã¿ã¦ã»ããã§ãã
宣ä¼
id:kakku22 ã¨ç§ã®ä¸»å¬ã§ããã³ãºãªã³å½¢å¼ã®Redash Meetup #0 ã12/19(ç«)ã«éå¬ãã¾ãããããããããã¨ã«ãã£ã³ã»ã«å¾ ã¡ãåºã¦ãã¾ãã
ãã³ãºãªã³ã¤ãã³ãã«ã¤ãã¦ã¯æ¥å¹´1æã«åæ¼ãè¨ç»ãã¦ãã¾ãã®ã§ãä»åäºå®ãåããªãã£ããããã£ã³ã»ã«å¾ ã¡ããç¹°ãä¸ãããªãã£ãæ¹ããæ¹ãã¦åå ãæ¤è¨ãã¦ããã ããã¨ããããã§ãã
ã¾ããä»å¾ã¯ãã³ãºãªã³ã¤ãã³ãã§ã¯ãªããå社ã®å°å ¥äºä¾ãæåã失æãå«ãã¦å ±æã§ãããããªä¼ç»ãæ¤è¨ãã¦ããã¾ãã®ã§ãRedashã«èå³ãããããã¯ããããããã°Connpassã®Redash Meetupã°ã«ã¼ãã«åå ãã¦ã¿ã¦ãã ããã
ãã®ã°ã«ã¼ãã«åå ãã¦ããã¨ã次åã®ãã³ãºãªã³ãå«ããä»å¾ã®ã¤ãã³ãæ¥ç¨ããã§ãã¯ãããããªãã¨æãã¾ãã