Commit 9274d990 authored by platyhouse's avatar platyhouse

.

parent 3560818d
grep -Fxq 'export PATH=$PATH:/root/pty_centos.git' /etc/bashrc || echo 'export PATH=$PATH:/root/pty_centos.git' >> /etc/bashrc
<?php
// CLI로 실행해야 하므로 PHP SAPI 확인
if (php_sapi_name() !== 'cli') {
exit("이 스크립트는 CLI에서만 실행 가능합니다.\n");
}
// 사용자로부터 인자 입력받기
if ($argc < 2) {
exit("사용법: php backup.php [database_name]\n");
}
$date = date("Ymd_His");
$databaseName = $argv[1];
$backupDir = "$databaseName";
$dumpFile = "$databaseName/{$databaseName}_{$date}.sql";
$zipFile = __DIR__ . "/{$databaseName}_{$date}.tgz";
// MySQL 설정 (환경에 맞게 수정)
$mysqlHost = 'localhost';
$mysqlUser = 'root';
$mysqlPassword = 'Tmxhfl!!00';
// 디렉터리 생성
if (!is_dir($backupDir)) {
mkdir($backupDir, 0755, true);
}
// MySQL 덤프 실행
echo "MySQL 덤프 생성 중...\n";
$dumpCommand = sprintf(
'mysqldump -h%s -u%s -p%s %s > %s',
escapeshellarg($mysqlHost),
escapeshellarg($mysqlUser),
escapeshellarg($mysqlPassword),
escapeshellarg($databaseName),
escapeshellarg($dumpFile)
);
exec($dumpCommand, $output, $resultCode);
if ($resultCode !== 0) {
exit("MySQL 덤프 실패: $dumpCommand\n");
}
echo "MySQL 덤프 생성 완료: $dumpFile\n";
// 폴더 압축
echo "폴더 압축 중...\n";
$zipCommand = sprintf(
'tar cvzf %s %s',
escapeshellarg($zipFile),
escapeshellarg($backupDir)
);
exec($zipCommand, $output, $resultCode);
if ($resultCode !== 0) {
exit("폴더 압축 실패: $zipCommand\n");
}
echo "폴더 압축 완료: $zipFile\n";
// 결과 출력
echo "백업 완료!\n";
echo "SQL 덤프 파일: $dumpFile\n";
echo "압축 파일: $zipFile\n";
<?php
// CLI에서 폴더 경로 입력 받기
$folderPath = isset($argv[1]) ? $argv[1] : "";
if ($folderPath === "") {
// 현재 디렉토리 설정
$folderPath = getcwd();
}
if (!is_dir($folderPath)) {
die("입력한 경로가 유효한 폴더가 아닙니다.\n");
}
// 현재 폴더의 하위 폴더 목록 가져오기
$folders = array_filter(glob($folderPath . DIRECTORY_SEPARATOR . '*'), 'is_dir');
if (empty($folders)) {
die("현재 디렉토리에 하위 폴더가 없습니다.\n");
}
$folderData = []; // 각 폴더의 데이터를 저장할 배열
// 각 폴더의 최신 파일 날짜 계산
foreach ($folders as $folder) {
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($folder, RecursiveDirectoryIterator::SKIP_DOTS)
);
$latestTimestamp = 0; // 각 폴더의 최신 날짜 저장
$latestFilePath = ""; // 최신 파일의 경로 저장
foreach ($iterator as $file) {
if ($file->isFile()) {
$fileCreationTime = filectime($file->getPathname());
if ($fileCreationTime > $latestTimestamp) {
$latestTimestamp = $fileCreationTime;
$latestFilePath = $file->getPathname();
}
}
}
$folderName = basename($folder);
$folderData[] = [
'folderName' => $folderName,
'latestTimestamp' => $latestTimestamp,
'latestFilePath' => $latestFilePath ?: "No files"
];
}
// 최신 파일 날짜 기준으로 정렬 (오래된 것이 아래로)
usort($folderData, function ($a, $b) {
if ($a['latestTimestamp'] == $b['latestTimestamp']) {
return 0;
}
return ($a['latestTimestamp'] > $b['latestTimestamp']) ? -1 : 1; // 최신 파일 날짜가 오래된 것이 아래로
});
// 결과 출력
echo str_repeat("=", 120) . "\n";
printf("| %-30s | %-20s | %-40s |\n", "Folder Name", "Latest File Date", "File Path");
echo str_repeat("=", 120) . "\n";
foreach ($folderData as $data) {
$latestDate = $data['latestTimestamp'] > 0 ? date("Y-m-d H:i:s", $data['latestTimestamp']) : "N/A";
printf(
"| %-30s | %-20s | %-40s |\n",
$data['folderName'],
$latestDate,
$data['latestFilePath']
);
}
echo str_repeat("=", 120) . "\n";
<?php
// MySQL 연결 설정
$host = 'localhost';
$user = 'root';
$password = 'Tmxhfl!!00';
// 6개월 전 날짜 계산
$sixMonthsAgo = date('Y-m-d H:i:s', strtotime('-6 months'));
// MySQL 연결
$conn = new mysqli($host, $user, $password);
if ($conn->connect_error) {
die("MySQL 연결 실패: " . $conn->connect_error . "\n");
}
// 쿼리 실행
$query = "
SELECT table_schema AS database_name, MAX(update_time) AS last_used
FROM information_schema.tables
WHERE table_schema NOT IN ('mysql', 'information_schema', 'performance_schema', 'sys')
GROUP BY table_schema
# HAVING MAX(update_time) < '$sixMonthsAgo' OR MAX(update_time) IS NULL
ORDER BY last_used DESC;
";
$result = $conn->query($query);
if (!$result) {
die("쿼리 실행 실패: " . $conn->error . "\n");
}
// 결과 출력
echo str_repeat("=", 80) . "\n";
printf("| %-30s | %-20s | %-15s |\n", "Database Name", "Last Used", "Days Since");
echo str_repeat("=", 80) . "\n";
while ($row = $result->fetch_assoc()) {
$databaseName = $row['database_name'];
$lastUsed = isset($row['last_used']) ? $row['last_used'] : 'Never used';
if ($lastUsed !== 'Never used') {
$daysElapsed = floor((time() - strtotime($lastUsed)) / (60 * 60 * 24));
printf("| %-30s | %-20s | %-15s |\n", $databaseName, $lastUsed, "$daysElapsed days");
} else {
printf("| %-30s | %-20s | %-15s |\n", $databaseName, "Never used", "N/A");
}
}
echo str_repeat("=", 80) . "\n";
// MySQL 연결 종료
$conn->close();
#!/usr/bin/php
<?php
$rootDir = $argv[1];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment