database backup

Database backup includes fullbackup, differential backup and incremental backup. This name is given in terms of “what data to back up”.

full backup
The easiest and the basis of all backups is a full backup. It literally backs up all the data held by the system at one point in time. Therefore, with this backup file, it is possible to recover all the data at that time.

This is a story, but if it is always possible to take a full backup during an active backup, the backup operation will be extreamly simple. Because, as mentioned above, data recovery will end easily if it is this.

Disadvantages of full backup
Cost1: It takes a long time to backup
The backup takes a long time to back up all the data in the system. Although some reductions can be made by excluding data that does not change, such as read-only files, it is necessary to include them in the backup target, since the core business data is usually change daily.

Cost: The load on resources is large
The fact that the data to be backed up is large means that a large number of read operations occur on the disk where the data is stored during the backup. Therefore, backup processing consumes a large amount of resources, including disk and server CPUs, and, if backup is performed via a network, network connections. Threfore, parallel execution of other processes during backup is not a pratical operation. A full backup consumes the most resources of the backup.

Cost: need to stop service
In general, shut down the software such as DBMS and stop the service before acquiring a full backup. This is because you must obtain backups while maintaining data integrity. However, there are not many systems that can stop service frequently.

Differential backup
Differential backup, as the name suggests, is a method of backup only the changes from the previous full backup.

Using differential backup increases the recovery procedure by one, but instead reduces the time required for backup because the data requried for daily backup is smaller. The impact on resources is also reduced accordingly.

Incremental backup
The thrd backup method is incremental backup. This is a smart version of the differential backup without any waste. Earlier, with differential backup files, there were many files that were unnecessary for recovery. That is because the information contained in these files is the same. If this redundancy is eliminated, the data to be backuped up will be less and the backup time will be shorter.

Perlで日付を表示

Time::Pieceを使う方法

#!/usr/bin/perl --
use Time::Piece;

my $t = localtime;
print $t->ymd;

上手くいかない。。

unixのdateコマンドを使用

#!/usr/bin/perl --

print qx(date "+%Y/%m/%d %H:%M:%S");

ちゃんと表示はされます。

2019/04/02 09:00:25

#!/usr/bin/perl --

my ($sec, $min, $hour, $mday, $mon, $year) = (localtime(time))[0..5];
print "Content-type:text/html\n\n";
printf("%d/%02d/%02d %02d:%02d:%02d\n", $year + 1900, $mon + 1, $mday, $hour, $min, $sec);

こちらも行けますねー

DBIで、mysqlにinsert

mysql> create table name(
-> name varchar(255),
-> password varchar(255)
-> );
Query OK, 0 rows affected (0.07 sec)

#!/usr/bin/perl --
use strict;
use utf8;
use warnings;
use CGI;
use DBI;

my $q = new CGI;
my $param1 = $q->param('name');
my $param2 = $q->param('password');

print "Content-type:text/html\n\n";
print "<html>\n";
print "<head></head>\n";
print "<form action=\"/cgi-bin/test2.cgi\">";
print "<label for=\"name\">お名前:</label>";
print "$param1<br>";
print "<label for=\"password\">パスワード:</label>";
print "$param2<br>";
print "<input type=\"submit\" value=\"送信\">";
print "</form>";
print "</html>";

my $user = 'root';
my $passwd = '';
my $db = DBI->connect('DBI:mysql:test:localhost', $user, $passwd);
my $sth = $db->prepare("INSERT INTO name(name, password) VALUES (?, ?)");
# $db->do("set names utf8");
$sth->execute($param1, $param2);

$sth->finish;
$db->disconnect;

print("finish\n");

mysql> select * from name;
Empty set (0.00 sec)

mysql> select * from name;
+——+———-+
| name | password |
+——+———-+
| hoge | hogehoge |
+——+———-+
1 row in set (0.00 sec)

perlでhiddenで送付する

/var/www/html/test.html

<!DOCTYPE html>
<meta charset="utf-8">
<style>
#errorMessage {
	color: red;
}
</style>
<form action="/cgi-bin/test.cgi">
<div id="errorMessage"></div>

<label for="name">お名前:</label>
<input name="name" id="name" required><br>
<label for="password">パスワード:</label>
<input type="password" name="password" id="password" required><br>
<label for="passwordConfirm">パスワード(確認):</label>
<input type="password" name="confirm" id="confirm" oninput="CheckPassword(this)"><br>
<input type="submit" value="送信">
</form>
<script>
		function CheckPassword(confirm){
			var input1 = password.value;
			var input2 = confirm.value;

			if (input1 != input2){
				confirm.setCustomValidity("入力値が一致しません");
			} else{
				confirm.setCustomValidity('');
			}
		}
</script>

/var/www/cgi-bin/test.cgi

#!/usr/bin/perl --
use strict;
use utf8;
use warnings;
use CGI;

my $q = new CGI;
my $param1 = $q->param('name');
my $param2 = $q->param('password');

print "Content-type:text/html\n\n";
print "<html>\n";
print "<head></head>\n";
print "<form action=\"/cgi-bin/test2.cgi\">";
print "<input type=\"hidden\" value=\"$param1\" name=\"name\"></input>";
print "<input type=\"hidden\" value=\"$param2\" name=\"password\"></input>";
print "<label for=\"name\">お名前:</label>";
print "$param1<br>";
print "<label for=\"password\">パスワード:</label>";
print "$param2<br>";
print "<input type=\"submit\" value=\"送信\">";
print "</form>";
print "</html>";

/var/www/cgi-bin/test2.cgi

#!/usr/bin/perl --
use strict;
use utf8;
use warnings;
use CGI;

my $q = new CGI;
my $param1 = $q->param('name');
my $param2 = $q->param('password');

print "Content-type:text/html\n\n";
print "<html>\n";
print "<head></head>\n";
print "<form action=\"/cgi-bin/test2.cgi\">";
print "<label for=\"name\">お名前:</label>";
print "$param1<br>";
print "<label for=\"password\">パスワード:</label>";
print "$param2<br>";
print "<input type=\"submit\" value=\"送信\">";
print "</form>";
print "</html>";

hiddenで送ります。

シェルの実行権限

./test.sh

#!/bin/sh
echo "Hello, World!"

[vagrant@localhost test]$ sed ‘s/\r//’ test.sh
#!/bin/sh
echo “Hello, World!”[vagrant@localhost test]$ ./test.sh
-bash: ./test.sh: 許可がありません
[vagrant@localhost test]$ ls -l
合計 8
-rw-rw-r– 1 vagrant vagrant 219 3月 31 16:33 2019 index.php
-rw-rw-r– 1 vagrant vagrant 31 4月 1 20:34 2019 test.sh

パーミッションは664。644に変えてみる。

[vagrant@localhost test]$ chmod 644 test.sh
[vagrant@localhost test]$ ./test.sh
-bash: ./test.sh: 許可がありません

やっぱり755でないと駄目なのか。。
モード(数字)|モード(アルファベット)|権限
4|r|読み取り
2|w|書き込み
1|x|実行

chmod +x というのは、実行権限を与える、ということね。

[vagrant@localhost test]$ chmod u+x test.sh
[vagrant@localhost test]$ ./test.sh
Hello, World!
[vagrant@localhost test]$ chmod u-x test.sh
[vagrant@localhost test]$ ./test.sh
-bash: ./test.sh: 許可がありません

なるほど、実行権限か~

Perlのinput formの画面遷移

入力画面
/var/www/html/test.html

<!DOCTYPE html>
<meta charset="utf-8">
<style>
#errorMessage {
	color: red;
}
</style>
<form action="/cgi-bin/test.cgi">
<div id="errorMessage"></div>

<label for="name">お名前:</label>
<input name="name" id="name" required><br>
<label for="password">パスワード:</label>
<input type="password" name="password" id="password" required><br>
<label for="passwordConfirm">パスワード(確認):</label>
<input type="password" name="confirm" id="confirm" oninput="CheckPassword(this)"><br>
<input type="submit" value="送信">
</form>
<script>
		function CheckPassword(confirm){
			var input1 = password.value;
			var input2 = confirm.value;

			if (input1 != input2){
				confirm.setCustomValidity("入力値が一致しません");
			} else{
				confirm.setCustomValidity('');
			}
		}
</script>

受け手のページ(確認画面)
/var/www/cgi-bin/test.cgi

#!/usr/bin/perl --
use strict;
use utf8;
use warnings;
use CGI;

my $q = new CGI;
my $param1 = $q->param('name');
my $param2 = $q->param('password');

print "Content-type:text/html\n\n";
print "<html>\n";
print "<head></head>\n";
print "<input type=\"hidden\" value=\"$param1\" name=\"name\"></input>";
print "<input type=\"hidden\" value=\"$param2\" name=\"password\"></input>";
print "<form action=\"/cgi-bin/test2.cgi\">";
print "<label for=\"name\">お名前:</label>";
print "$param1<br>";
print "<label for=\"password\">パスワード:</label>";
print "$param2<br>";
print "<input type=\"submit\" value=\"送信\">";
print "</form>";
print "</html>";

一応、受け渡しはされてますが、、、

なんかイマイチ。。

メールの型チェック

$var="hoge@gmail.com";
if(filter_var($var, FILTER_VALIDATE_EMAIL)){
	echo $var . "正しいメール<br>";
} else {
	echo $var . "不正のメール<br>";
}

こちらでも、できますねー

$var="hoge@gmail.com";
if(preg_match('/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/iD', $var)){
	echo $var . "正しいメール<br>";
} else {
	echo $var . "不正のメール<br>";
}

URLの型チェック

filter_var: filter data by specified filter

$var="https://www.google.com/";
if(filter_var($var, FILTER_VALIDATE_URL)){
	echo $var . "正しいURL<br>";
} else {
	echo $var . "不正のURL<br>";
}

時間型のチェック

$var="10:53";
if($var === date('H:i', strtotime($var))){
	echo $var . "正しい時間型<br>";
} else {
	echo $var . "不正の時間型<br>";
}

なんか、くだらないなーと思うのは私だけ??

日付の型チェック

$var="2019/2/19";
if(preg_match('/^([1-9][0-9]{3})\/([1-9]{1}|1[0-2]{1}|[0][1-9])\/([1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]{1}|[0][1-9])$/', $var)){
	echo $var . "正しい日付<br>";
} else {
	echo $var . "不正の日付<br>";
}

ただ、これvarが2018/2/29でも、2019/2/29でも正しいって出てしまうし、30日しかない月でも31日って入力されてもOKになってしまうんだよね。

まーライブラリーであるんだろうけど。ロジックとしてはわかりました。