之前由于误删数据,需要恢复,但是不能影响线上服务:

public function insertData()
{
$number = 11020095;
$interval = 500000;
$file_name = ' /tmp/table_name_12220095.sql';
for ($i = 1; $i < 100; $i++) {
$samll = $number - $interval * $i;
if ($samll > 0) {
$big = $samll + $interval;
echo sprintf('mysqldump -h db_host -u db_user -p db_password table_name --where="id>=%s and id<%s" >%s', $samll, $big, $file_name) . PHP_EOL;
sleep(1);
}
}
}

批量检查遗漏的ID:

public function checkNotExist()
{
// 每次调用之前清空之前的数据
file_put_contents(LOG_ROOT . '/Log/not_exist.txt', '');
$number = 12270095;
$intrval = 10000;
for ($i = 0; $i < $number; $i++) {
$small = $i * $intrval;
$big = $small + $intrval - 1;
$arr = range($small, $big);
if ($big > $number) {
return $this->writeJson(sprintf('已完成,大值%s,小值%s', $big, $small));
}
$ids = XxModel::create()->where('id', [$small, $big], 'between')->column('id');
$str = '';
if (empty($ids)) {
$str = implode(',', $arr);
} elseif (count($ids) != $intrval) {
$str = implode(',', array_diff($arr, $ids));
}
if ($str) {
file_put_contents(LOG_ROOT . '/Log/not_exist.txt', $str . PHP_EOL, FILE_APPEND);
}
// usleep(100);
}
}