fix: backup — MYSQL_PWD statt -p Flag, SSH-Key optional
Passwort via MYSQL_PWD-Env statt -p vermeidet die mysqldump-Warnung und ist sicherer. BACKUP_SSH_KEY_PATH ist jetzt optional: wenn leer, wird kein -i übergeben und SSH nutzt seine eigene Konfiguration (~/.ssh/config, ssh-agent). So funktionieren SSH-Config-Aliases (z.B. 'strato_1') ohne Key-Override. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+4
-4
@@ -14,7 +14,7 @@ async function runBackup(): Promise<void> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const [, sshHost, remotePath] = match;
|
const [, sshHost, remotePath] = match;
|
||||||
const rawKeyPath = process.env.BACKUP_SSH_KEY_PATH || '/app/.ssh/id_rsa';
|
const rawKeyPath = process.env.BACKUP_SSH_KEY_PATH || '';
|
||||||
const keyPath = rawKeyPath.startsWith('~')
|
const keyPath = rawKeyPath.startsWith('~')
|
||||||
? rawKeyPath.replace('~', process.env.HOME || '/root')
|
? rawKeyPath.replace('~', process.env.HOME || '/root')
|
||||||
: rawKeyPath;
|
: rawKeyPath;
|
||||||
@@ -29,17 +29,17 @@ async function runBackup(): Promise<void> {
|
|||||||
const dbName = process.env.DB_NAME || 'sternwarte';
|
const dbName = process.env.DB_NAME || 'sternwarte';
|
||||||
|
|
||||||
const sshOpts = [
|
const sshOpts = [
|
||||||
'-i', keyPath,
|
...(keyPath ? ['-i', keyPath] : []),
|
||||||
'-o', 'StrictHostKeyChecking=no',
|
'-o', 'StrictHostKeyChecking=no',
|
||||||
'-o', 'BatchMode=yes',
|
'-o', 'BatchMode=yes',
|
||||||
];
|
];
|
||||||
|
|
||||||
await new Promise<void>((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
const dump = spawn('mysqldump', [
|
const dump = spawn('mysqldump', [
|
||||||
`-h${dbHost}`, `-P${dbPort}`, `-u${dbUser}`, `-p${dbPass}`,
|
`-h${dbHost}`, `-P${dbPort}`, `-u${dbUser}`,
|
||||||
`--ignore-table=${dbName}.beos`,
|
`--ignore-table=${dbName}.beos`,
|
||||||
dbName,
|
dbName,
|
||||||
]);
|
], { env: { ...process.env, MYSQL_PWD: dbPass } });
|
||||||
const gzip = spawn('gzip');
|
const gzip = spawn('gzip');
|
||||||
const ssh = spawn('ssh', [...sshOpts, sshHost, `cat > ${remotePath}/${filename}`]);
|
const ssh = spawn('ssh', [...sshOpts, sshHost, `cat > ${remotePath}/${filename}`]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user