Skip to content

Commit ab77071

Browse files
committed
Merge pull request #170 from akmetainfo/SqlSelectiveBackup
Selective backup
2 parents a93137e + 7c89f54 commit ab77071

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

export/database/backup.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
mysql corpora < copy_nulled_tables.sql
4+
5+
mysqldump \
6+
--ignore-table=${MySqlDatabaseName}.users \
7+
--ignore-table=${MySqlDatabaseName}.user_tokens \
8+
corpora > dump.sql
9+
10+
sed -i 's/`users_for_selective_backup`/`users`/g' dump.sql
11+
sed -i 's/`user_tokens_for_selective_backup`/`user_tokens`/g' dump.sql
12+
13+
#gzip dump.sql
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
SET NAMES utf8;
2+
3+
-- table `users` --> `users_for_selective_backup`
4+
5+
TRUNCATE TABLE `users_for_selective_backup`;
6+
7+
INSERT INTO `users_for_selective_backup` (
8+
`user_id`,
9+
`user_name`,
10+
`user_passwd`,
11+
`user_email`,
12+
`user_reg`,
13+
`user_shown_name`,
14+
`user_team`,
15+
`user_level`,
16+
`user_shown_level`,
17+
`user_rating10`,
18+
`show_game`
19+
) SELECT
20+
`user_id`,
21+
`user_name`,
22+
'' AS `user_passwd`,
23+
'' AS `user_email`,
24+
`user_reg`,
25+
`user_shown_name`,
26+
`user_team`,
27+
`user_level`,
28+
`user_shown_level`,
29+
`user_rating10`,
30+
`show_game`
31+
FROM `users`
32+
WHERE 1 = 1;
33+
34+
-- table `user_tokens` --> `user_tokens_for_selective_backup`
35+
36+
TRUNCATE TABLE `user_tokens_for_selective_backup`;
37+
38+
INSERT INTO `user_tokens_for_selective_backup` (
39+
`user_id`,
40+
`token`,
41+
`timestamp`
42+
) SELECT
43+
`user_id`,
44+
0 AS `token`,
45+
`timestamp`
46+
FROM `user_tokens`
47+
WHERE 1 = 1;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
use Phinx\Migration\AbstractMigration;
4+
5+
class AddTablesForSelectiveBackup extends AbstractMigration
6+
{
7+
public function up()
8+
{
9+
$this->execute("CREATE TABLE `users_for_selective_backup` (
10+
`user_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
11+
`user_name` varchar(120) NOT NULL,
12+
`user_passwd` varchar(32) NOT NULL,
13+
`user_email` varchar(100) NOT NULL,
14+
`user_reg` int(10) unsigned NOT NULL,
15+
`user_shown_name` varchar(120) NOT NULL,
16+
`user_team` smallint(5) unsigned NOT NULL,
17+
`user_level` tinyint(3) unsigned NOT NULL,
18+
`user_shown_level` tinyint(3) unsigned NOT NULL,
19+
`user_rating10` int(10) unsigned NOT NULL,
20+
`show_game` tinyint(3) unsigned NOT NULL,
21+
PRIMARY KEY (`user_id`),
22+
KEY `user_team` (`user_team`),
23+
KEY `user_rating10` (`user_rating10`)
24+
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;");
25+
26+
$this->execute("CREATE TABLE `user_tokens_for_selective_backup` (
27+
`user_id` SMALLINT(5) UNSIGNED NOT NULL,
28+
`token` INT(10) UNSIGNED NOT NULL,
29+
`timestamp` INT(10) UNSIGNED NOT NULL,
30+
KEY `user_id` (`user_id`)
31+
) ENGINE=INNODB DEFAULT CHARSET=utf8;");
32+
}
33+
34+
public function down()
35+
{
36+
$this->dropTable("users_for_selective_backup");
37+
$this->dropTable("user_tokens_for_selective_backup");
38+
}
39+
}

0 commit comments

Comments
 (0)