ギャバンITサービス
お菓子の家が作れるシステムエンジニアです

DOSバッチ処理 - バックアップ処理

毎日定期的に動く処理はDOSバッチで動かす。 バックアップ処理の道具 ツール 内容 参考URL fastcopy 同期・差分コピーをGUI・コマンドラインで行う。 https://fastcopy.jp/ 作者さんありがとう。 バックアップのサンプル 毎朝バックアップ領域(Y:\98_backup\Y_backup)へ同期コピーする処理。 ドライブ接続ができてれば動く。 ショートカットやらメモやら、普段使うデータは「ワイのドライブ」なのでY:をドライブレターにして利用。 バックアップ領域はsambaで動くlinuxのフォルダ。GV_EXCLUDEには、バックアップ除外対象を書いてある。 macでsmb接続すると「.DS_Store」って隠しファイルがいっぱいできるので除外。 最後のほうでバックアップ領域はttlマクロを使って暗号化zip作成し、explorerで圧縮したファイルの置き場(S:\nariHTTP\configBackup\11_win7proSVM2)を開く。 昔はexplzhの 定型圧縮 をやってたけど、どうしてもlinuxのroot権限使って取りたいバックアップがあったのと、zipに100文字以上の暗号化文字列使いたかったのでやめた。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 rem ----------------------------------------------------------------------------- rem Yドライブのバックアップ処理実施 rem rem ----------------------------------------------------------------------------- rem -----------環境作成のためのディレクトリパス SET FASTCOPY="Y:\99_tools\FastCopy\fastcopy.exe" SET FSCP_LOG="Y:\95_log\GVISwindows-fastcopy.log" set TTPMAC="C:\Program Files (x86)\teraterm\ttpmacro.exe" set GCP_macro=Y:\94_connect\connect\GCP set LCL_macro=Y:\94_connect\connect\VM set LCL_maint=Y:\94_connect\netuse\LetS-netuse-118_naFSLinux.bat SET From11="Y:\91_shortcut" SET From12="Y:\92_dockerwk" SET From13="Y:\93_netuse" SET From14="Y:\94_connect" SET From15="Y:\95_log" SET From16="Y:\96_maint_tools" SET From17="Y:\97_mailwork" SET From18="Y:\99_tools" SET From19="Y:\etc" SET From1A="Y:\GavannIT-ID.xlsx" SET From1B="Y:\memo.txt" SET From21="C:\Users\nari\Desktop" SET From22="C:\nari" SET BackupTo1="Y:\98_backup\Y_backup\" SET GV_EXCLUDE="System Volume Information\ ; $RECYCLE.BIN\ ; .DS_Store;._* ; lost+found\ ; nariDockerVol\" rem start /wait %LCL_maint% if not exist %BackupTo1% ( exit ) if not exist Y:\ ( exit ) rem pause del /F /Q %FSCP_LOG% rem ------Y data %FASTCOPY% /cmd=sync /estimate /verify /force_start /force_close /log /logfile=%FSCP_LOG% /bufsize=64 /exclude=%GV_EXCLUDE% %From11% /to=%BackupTo1% %FASTCOPY% /cmd=sync /estimate /verify /force_start /force_close /log /logfile=%FSCP_LOG% /bufsize=64 /exclude=%GV_EXCLUDE% %From12% /to=%BackupTo1% %FASTCOPY% /cmd=sync /estimate /verify /force_start /force_close /log /logfile=%FSCP_LOG% /bufsize=64 /exclude=%GV_EXCLUDE% %From13% /to=%BackupTo1% %FASTCOPY% /cmd=sync /estimate /verify /force_start /force_close /log /logfile=%FSCP_LOG% /bufsize=64 /exclude=%GV_EXCLUDE% %From14% /to=%BackupTo1% %FASTCOPY% /cmd=sync /estimate /verify /force_start /force_close /log /logfile=%FSCP_LOG% /bufsize=64 /exclude=%GV_EXCLUDE% %From15% /to=%BackupTo1% %FASTCOPY% /cmd=sync /estimate /verify /force_start /force_close /log /logfile=%FSCP_LOG% /bufsize=64 /exclude=%GV_EXCLUDE% %From16% /to=%BackupTo1% %FASTCOPY% /cmd=sync /estimate /verify /force_start /force_close /log /logfile=%FSCP_LOG% /bufsize=64 /exclude=%GV_EXCLUDE% %From17% /to=%BackupTo1% %FASTCOPY% /cmd=sync /estimate /verify /force_start /force_close /log /logfile=%FSCP_LOG% /bufsize=64 /exclude=%GV_EXCLUDE% %From18% /to=%BackupTo1% %FASTCOPY% /cmd=sync /estimate /verify /force_start /force_close /log /logfile=%FSCP_LOG% /bufsize=64 /exclude=%GV_EXCLUDE% %From19% /to=%BackupTo1% %FASTCOPY% /cmd=sync /estimate /verify /force_start /force_close /log /logfile=%FSCP_LOG% /bufsize=64 /exclude=%GV_EXCLUDE% %From1A% /to=%BackupTo1% %FASTCOPY% /cmd=sync /estimate /verify /force_start /force_close /log /logfile=%FSCP_LOG% /bufsize=64 /exclude=%GV_EXCLUDE% %From1B% /to=%BackupTo1% %FASTCOPY% /cmd=sync /estimate /verify /force_start /force_close /log /logfile=%FSCP_LOG% /bufsize=64 /exclude=%GV_EXCLUDE% %From21% /to=%BackupTo1% %FASTCOPY% /cmd=sync /estimate /verify /force_start /force_close /log /logfile=%FSCP_LOG% /bufsize=64 /exclude=%GV_EXCLUDE% %From22% /to=%BackupTo1% rem -----------Make zip -------------------------- %TTPMAC% %LCL_macro%\_118_naFSLinux-SSH-MakeTar_Y.ttl explorer S:\nariHTTP\configBackup\11_win7proSVM2 rem pause exit

rtx1210でsyslog監視

rtx1210は高価だけどネットワークの勉強をするにはいい教材。 業務でも稀に箱モノの設定することがあるから、頭の体操にもなる。 ブラウザでログインしてポチポチ設定することから初め、設定ファイルを入れ込めば複雑なことができることもわかった。 コマンドラインでいろいろできることがわかったとき、設定ファイルがその積み上げ結果というのもわかった。 ブラウザから設定保存するとconfig0.txtっていうファイルが作成できる。 ログ監視 この設定ファイルに以下の内容を追記して、ログ監視してみる。 やってることはembedded fileっていうのを定義しておき、この内容をルータ起動時から実行させる。 ヤマハのページにsyslog監視のサンプルがあった。他にもいくつかググって方法を探し、試しながら作成。 検出したい文字列は、いったんlinuxの監視処理で使ってたものをそのまま流用。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 embedded file tmp.txt <<EOF --[[ ●SYSLOG 監視スクリプト-gvis SYSLOG を監視し、特定の文字列が含まれたログを検出したら、 指定したshow log コマンドの出力結果を管理者にメールで 送信するスクリプト。 メール本文には監視実施日の日付に検出された特定の文字列の履歴を含みます。 原本はyamahaさまの以下のページにあったものから改造作成し、 複数文字列を監視するようにしている。 https://network.yamaha.com/setting/router_firewall/monitor/lua_script/syslog ]] --------------------------## 設定値 ##-------------------------------- -- 検出したい SYSLOG の文字列パターン ptn_tbl = { -- ★ "error", "ERROR", "Error", "fail", "Fail", "FAIL", "panic", "Panic", "PANIC", "warn", "Warn", "WARN", "respond", "connect", "TUNNEL", "Login", "Logout", "Restarting router" } -- ptn の文字列パターンを検出したときに結果を通知する show コマンド cmd_whenFind = "show log reverse" -- ★ -- メールの設定 mail_tbl = { -- ★ smtp_address = "smtp.xxxx.jp", from = "xxxx@gavann-it.com", to = "xxxx@gavann-it.com" } -- メールの送信に失敗したときに出力する SYSLOG のレベル (info, debug, notice) log_level = "info" -- ★ ----------------------## 設定値ここまで ##---------------------------- ------------------------------------------------------------ -- コマンドを実行結果を出力する関数 -- ------------------------------------------------------------ function exec_command(cmd) local rtn, str rtn, str = rt.command(cmd) if (not rtn) or (not str) then str = "実行失敗\r\n" end return rtn, string.format("# %s\r\n%s\r\n", cmd, str) end ------------------------------------------------------------ -- 現在の日時を取得する関数 -- ------------------------------------------------------------ function time_stamp() local t t = os.date("*t") return string.format("%d/%02d/%02d %02d:%02d:%02d", t.year, t.month, t.day, t.hour, t.min, t.sec) end ------------------------------------------------------------ -- 今日の日付を取得する関数 -- ------------------------------------------------------------ function date_today() local today today = os.date("*t") return string.format("%d/%02d/%02d", today.year, today.month, today.day) end ------------------------------------------------------------ -- メインルーチン -- ------------------------------------------------------------ local rtn, logstr while (true) do -- SYSLOGから何か追加された文字列を格納するまで待つ rtn, logstr = rt.syslogwatch(".*") -- SYSLOG文字列が何か拾えたらマッチする文字列を探す if (rtn) and (logstr) then for i, str in ipairs(logstr) do for j, ptn in ipairs(ptn_tbl) do -- マッチする文字列があったらメールする if string.find(str, ptn) ~= nil then mail_tbl.text = string.format("ログに検索文字列が検出されました。\r\n検索文字列: \"%s\"\r\n\r\n", ptn) runCmd = cmd_whenFind .. " | grep " .. ptn .. " | grep " .. date_today() rtn, str = exec_command(runCmd) mail_tbl.text = mail_tbl.text .. str mail_tbl.subject = string.format("auto)alertReport-Netlog-rtx1210 (%s)", time_stamp()) rtn = rt.mail(mail_tbl) if (not rtn) then rt.syslog(log_level, "failed to send mail. (syslogWatch-rtx1210lua)") end end end end end end EOF embedded fileの定義を起動時から実行するように設定ファイルに書いておくと、SYSLOGを監視してくれる。 ...

 ⭐️

ルータのためのsyslog設定

ルータのログはそんなにたくさん残るものでもない。 再起動したら消える。 ではローカルのlinuxに残せないか。 ログを残したいというよりも、VPNしたりsshしたときに特定のキーワードがログに出力されるから、それを監視させたいというのが一番最初の目的。 windowsで syslogdもどき を動かすこともできるけど、シェルスクリプトで書いたログ監視をそのまま使いたかったので使わない。 ローカルlinuxで動いているrsyslogdがログを受け付けてくれる。 172.16.17.xxは水際のルータ。機種はrtx1210で外側は固定IP。一般家庭で使うルータが1万円かそこらで買えるけど、勉強のためもあって6万円ほどで購入。そのぶんできることも多く、プログラム必要だけどログの監視とメール送信ができたり、サポート外だけどGoogle CloudにVPN接続する設定まで入れて使ってる。 rtxシリーズのsyslog解説。 ローカルlinuxで受け付けるよう設定したのが以下。 centos7の場合 最初はcentos6の頃からやってたけど設定ファイル古すぎてバックアップ残してない。 centos8の頃に使ってた/etc/rsyslog.confの設定。 設定は「:fromhost-ip, isequal, “172.16.17.xx”」っていう記述を足してsyslogのデーモン再起動したはず。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 # rsyslog configuration file # For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html # If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html #### MODULES #### # The imjournal module bellow is now used as a message source instead of imuxsock. $ModLoad imuxsock # provides support for local system logging (e.g. via logger command) $ModLoad imjournal # provides access to the systemd journal #$ModLoad imklog # reads kernel messages (the same are read from journald) #$ModLoad immark # provides --MARK-- message capability # Provides UDP syslog reception #$ModLoad imudp #$UDPServerRun 514 # Provides TCP syslog reception #$ModLoad imtcp #$InputTCPServerRun 514 $ModLoad imudp $UDPServerRun 514 $umask 0022 $FileCreateMode 0644 $DirCreateMode 0755 #### GLOBAL DIRECTIVES #### # Where to place auxiliary files $WorkDirectory /var/lib/rsyslog # Use default timestamp format $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat # File syncing capability is disabled by default. This feature is usually not required, # not useful and an extreme performance hit #$ActionFileEnableSync on # Include all config files in /etc/rsyslog.d/ $IncludeConfig /etc/rsyslog.d/*.conf # Turn off message reception via local log socket; # local messages are retrieved through imjournal now. $OmitLocalLogging on # File to store the position in the journal $IMJournalStateFile imjournal.state #### RULES #### # Log all kernel messages to the console. # Logging much else clutters up the screen. #kern.* /dev/console # Log anything (except mail) of level info or higher. # Don't log private authentication messages! *.info;mail.none;authpriv.none;cron.none;local0.none /var/log/messages # The authpriv file has restricted access. authpriv.* /var/log/secure # Log all the mail messages in one place. mail.* -/var/log/maillog # Log cron stuff cron.* /var/log/cron # Everybody gets emergency messages *.emerg :omusrmsg:* # Save news errors of level crit and higher in a special file. uucp,news.crit /var/log/spooler # Save boot messages also to boot.log local7.* /var/log/boot.log # Save network messages to network.log :fromhost-ip, isequal, "172.16.17.xx" /var/log/network_172.16.17.xx.log # ### begin forwarding rule ### # The statement between the begin ... end define a SINGLE forwarding # rule. They belong together, do NOT split them. If you create multiple # forwarding rules, duplicate the whole block! # Remote Logging (we use TCP for reliable delivery) # # An on-disk queue is created for this action. If the remote host is # down, messages are spooled to disk and sent when it is up again. #$ActionQueueFileName fwdRule1 # unique name prefix for spool files #$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible) #$ActionQueueSaveOnShutdown on # save messages to disk on shutdown #$ActionQueueType LinkedList # run asynchronously #$ActionResumeRetryCount -1 # infinite retries if host is down # remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional #*.* @@remote-host:514 # ### end of the forwarding rule ### ubuntu20の場合 無線LANの性能が低くなったなーと感じて買い換えたときに、syslogもいちおう残してみるかと思って設定追加。 ...

 ⭐️

teradata試験環境作成

2016年頃に業務でteradata利用することがあったので雰囲気確認のために実施。 日本ではあんまり使われてないのか、技術情報は全部英語提供。 なんとなく読めたので実施。 自分の作業はお客様に満足はいただけなかったかもしれないけど、DB操作はとても楽しかった。 当時見つけた解説ページ印刷。 もうリンク切れてるかも。 http://developer.teradata.com/database/articles/introduction-to-teradata-express-for-vmware-player 実際の作成したときのVM画面 サイトからVMイメージ取得して実行 teradataのサイトで登録するとダウンロードが可能になるのでログインしてvmイメージを取ってくる Teradata Vantage Express | Teradata Developers Portal downloads.teradata.com 取ってきたイメージは7zipになっているので展開する 展開してきたイメージの.vmxをvmplayerに読み込ませて実行する openSUSEの操作 openSUSEが動くのでroot/rootでログインして画面左下のComputerをクリックしてyast2から時計、KBDを設定 yast2からネットワークコンフィグレーションしてIPを設定する。ルーティング設定を変更するとOS再起動必要 /etc/hostsにlocalhostを127.0.0.1として登録しておく 800x600では狭いので、必要に応じてGUIの解像度を広げる OSユーザでログインしてサービス起動 rootユーザでログインし、teradataのサービスを起動する 1 2 3 4 TD-EXPRESS:~ # /etc/init.d/tpa start Teradata Database Initiator service is starting... Teradata Database Initiator service started successfully. TD-EXPRESS:~ # サービスが起動していることを確認する 1 2 3 4 TD-EXPRESS:~ # pdestate -a PDE state is RUN/STARTED. DBS state is 4: Logons are enabled - Users are logged on TD-EXPRESS:~ # コマンドラインのSQLツールを利用 接続確認する 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 TD-EXPRESS:~ # bteq Teradata BTEQ 15.10.00.03 for LINUX. PID: 9323 Copyright 1984-2015, Teradata Corporation. ALL RIGHTS RESERVED. Enter your logon or BTEQ command: .logon 127.0.0.1/dbc .logon 127.0.0.1/dbc Password: *** Logon successfully completed. *** Teradata Database Release is 15.10.00.06 *** Teradata Database Version is 15.10.00.07 *** Transaction Semantics are BTET. *** Session Character Set Name is 'ASCII'. *** Total elapsed time was 1 second. BTEQ -- Enter your SQL request or BTEQ command: select * from dbcinfo ; select * from dbcinfo ; *** Query completed. 3 rows found. 2 columns returned. *** Total elapsed time was 1 second. InfoKey InfoData ------------------------------ -------------------------------------------- LANGUAGE SUPPORT MODE Standard RELEASE 15.10.00.06 VERSION 15.10.00.07 BTEQ -- Enter your SQL request or BTEQ command: quit ; quit ; *** You are now logged off from the DBC. *** Exiting BTEQ... *** RC (return code) = 0 TD-EXPRESS:~ # テストユーザとテーブルを作る 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 TD-EXPRESS:~ # bteq Teradata BTEQ 15.10.00.03 for LINUX. PID: 9343 Copyright 1984-2015, Teradata Corporation. ALL RIGHTS RESERVED. Enter your logon or BTEQ command: .logon 127.0.0.1/dbc .logon 127.0.0.1/dbc Password: *** Logon successfully completed. *** Teradata Database Release is 15.10.00.06 *** Teradata Database Version is 15.10.00.07 *** Transaction Semantics are BTET. *** Session Character Set Name is 'ASCII'. *** Total elapsed time was 1 second. BTEQ -- Enter your SQL request or BTEQ command: CREATE user vmtest AS password=vmtest perm=524288000 spool=524288000; CREATE user vmtest AS password=vmtest perm=524288000 spool=524288000; *** User has been created. *** Total elapsed time was 2 seconds. BTEQ -- Enter your SQL request or BTEQ command: CREATE SET TABLE vmtest.test , NO FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL, CHECKSUM = DEFAULT ( Test_field1 INTEGER, Test_field2 INTEGER) PRIMARY INDEX ( Test_field1 ); CREATE SET TABLE vmtest.test , NO FALLBACK , NO BEFORE JOURNAL, NO AFTER JOURNAL, CHECKSUM = DEFAULT ( Test_field1 INTEGER, Test_field2 INTEGER) PRIMARY INDEX ( Test_field1 ); *** Table has been created. *** Total elapsed time was 1 second. BTEQ -- Enter your SQL request or BTEQ command: select * from vmtest.test ; select * from vmtest.test ; *** Query completed. No rows found. *** Total elapsed time was 1 second. BTEQ -- Enter your SQL request or BTEQ command: select count(*) from vmtest.test ; select count(*) from vmtest.test ; *** Query completed. One row found. One column returned. *** Total elapsed time was 1 second. Count(*) ----------- 0 BTEQ -- Enter your SQL request or BTEQ command: quit ; quit ; *** You are now logged off from the DBC. *** Exiting BTEQ... *** RC (return code) = 0 TD-EXPRESS:~ # データを投入する 1 2 3 4 5 6 7 8 9 10 11 12 13 14 a)show tables SELECT tablename, databasename FROM dbc.tables ; b)insert table by Teradata Studio Express SQL make on Excel and paste into .txt and Terminal window. insert into test values ( 00001, 00001) ; insert into test values ( 00002, 00002) ; : insert into test values (100000,100000) ; その他試行錯誤中で発見したコマンドライン service start /etc/init.d/tpa start service status pdestate -a other command 1 2 3 4 5 6 tpareset -f restarting verifypdisks tdatcmd ctl screen debug cnscons sql 1 2 3 bteq .logon 127.0.0.1/dbc quit

 ⭐️

スクリプト内の演算子

演算のメモ 1 2 3 4 5 6 + 加法 echo $(( 2 + 3 )) 5 - 減法 echo $(( 2 - 3 )) -1 / 除法 echo $(( 6 / 2 )) 3 * 乗法 echo $(( 2 * 3 )) 6 ** べき乗 echo $(( 2 ** 3 )) 8 % 余り echo $(( 2 % 3 )) 2 x++ インクリメント ...