docs: ask for the server password when the Mac copies backups at 17:00
A login item at 17:00 Iran time shows a password box and copies every dump still on the server. The password is not saved.
This commit is contained in:
@@ -122,6 +122,23 @@ cd /Users/rameen/Documents/dental/dyolink
|
||||
|
||||
It asks for the server password once and does not save it. It copies every `.dump` file from the server backup folder into `~/Documents/dental/nudentic-backups/` and prints the list. A good file is larger than a few kilobytes (the first successful dump was 574K).
|
||||
|
||||
### Every day at 17:00
|
||||
|
||||
Run that script once a day at **17:00 Iran time**, after the 16:00 server dump. One run copies every dump still on the server, including the 02:00 and 11:00 files, so it does not need to run three times. The Mac clock must be Iran time. If the Mac is asleep at 17:00, that run is skipped; the files stay on the server for 3 days, so the next afternoon the Mac is awake still copies them.
|
||||
|
||||
At 17:00 a password box appears on the Mac. Type the server password and click Copy. It is not saved. You must be logged in so the box can appear. Cancel skips that day’s copy.
|
||||
|
||||
Install the 17:00 job (this does not happen from git by itself):
|
||||
|
||||
```bash
|
||||
mkdir -p ~/Documents/dental/nudentic-backups ~/Library/LaunchAgents
|
||||
cp infrastructure/launchd/ir.nudentic.copy-prod-backup.plist ~/Library/LaunchAgents/
|
||||
launchctl bootout gui/$(id -u) ~/Library/LaunchAgents/ir.nudentic.copy-prod-backup.plist 2>/dev/null || true
|
||||
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/ir.nudentic.copy-prod-backup.plist
|
||||
```
|
||||
|
||||
Output goes to `~/Documents/dental/nudentic-backups/copy.log`.
|
||||
|
||||
---
|
||||
|
||||
## 3. Load the dump into the local database
|
||||
|
||||
25
infrastructure/launchd/ir.nudentic.copy-prod-backup.plist
Normal file
25
infrastructure/launchd/ir.nudentic.copy-prod-backup.plist
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>ir.nudentic.copy-prod-backup</string>
|
||||
<key>WorkingDirectory</key>
|
||||
<string>/Users/rameen/Documents/dental/dyolink</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/Users/rameen/Documents/dental/dyolink/infrastructure/scripts/copy-prod-backup.sh</string>
|
||||
</array>
|
||||
<key>StartCalendarInterval</key>
|
||||
<dict>
|
||||
<key>Hour</key>
|
||||
<integer>17</integer>
|
||||
<key>Minute</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
<key>StandardOutPath</key>
|
||||
<string>/Users/rameen/Documents/dental/nudentic-backups/copy.log</string>
|
||||
<key>StandardErrorPath</key>
|
||||
<string>/Users/rameen/Documents/dental/nudentic-backups/copy.log</string>
|
||||
</dict>
|
||||
</plist>
|
||||
4
infrastructure/scripts/copy-prod-backup-askpass.sh
Executable file
4
infrastructure/scripts/copy-prod-backup-askpass.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
# Shown by SSH when the copy runs with no terminal (the 17:00 Mac job).
|
||||
# Prints the password to SSH only. Does not save it.
|
||||
osascript -e 'text returned of (display dialog "Enter the nudentic server password." default answer "" with hidden answer buttons {"Cancel", "Copy"} default button "Copy" cancel button "Cancel" with title "Nudentic backup")'
|
||||
@@ -8,6 +8,12 @@ REMOTE="dyolink@185.243.48.140"
|
||||
REMOTE_DIR="/opt/dyolink/infrastructure/database/backups"
|
||||
DEST="${HOME}/Documents/dental/nudentic-backups"
|
||||
CONTROL="$(mktemp -u "${TMPDIR:-/tmp}/dyolink-backup-ssh.XXXXXX")"
|
||||
ASKPASS="$(cd "$(dirname "$0")" && pwd)/copy-prod-backup-askpass.sh"
|
||||
SSH_BASE=(
|
||||
-o ControlPath="$CONTROL"
|
||||
-o PreferredAuthentications=password
|
||||
-o PubkeyAuthentication=no
|
||||
)
|
||||
|
||||
cleanup() {
|
||||
ssh -o ControlPath="$CONTROL" -O exit "$REMOTE" >/dev/null 2>&1 || true
|
||||
@@ -17,11 +23,19 @@ trap cleanup EXIT
|
||||
|
||||
mkdir -p "$DEST"
|
||||
|
||||
echo "Connecting to ${REMOTE}. Enter the server password once."
|
||||
ssh -o ControlMaster=yes -o ControlPath="$CONTROL" -o ControlPersist=60 "$REMOTE" true
|
||||
# A terminal asks in the terminal. The 17:00 job has no terminal, so a password box is shown.
|
||||
if [ ! -t 0 ]; then
|
||||
export SSH_ASKPASS="$ASKPASS"
|
||||
export SSH_ASKPASS_REQUIRE=force
|
||||
echo "Waiting for the password box."
|
||||
else
|
||||
echo "Connecting to ${REMOTE}. Enter the server password once."
|
||||
fi
|
||||
|
||||
ssh -o ControlMaster=yes -o ControlPersist=60 "${SSH_BASE[@]}" "$REMOTE" true
|
||||
|
||||
FILES="$(
|
||||
ssh -o ControlPath="$CONTROL" "$REMOTE" \
|
||||
ssh "${SSH_BASE[@]}" "$REMOTE" \
|
||||
"ls -1 ${REMOTE_DIR}/*.dump 2>/dev/null" \
|
||||
|| true
|
||||
)"
|
||||
@@ -33,7 +47,7 @@ fi
|
||||
|
||||
while IFS= read -r FILE; do
|
||||
[ -z "$FILE" ] && continue
|
||||
scp -o ControlPath="$CONTROL" "${REMOTE}:${FILE}" "${DEST}/"
|
||||
scp "${SSH_BASE[@]}" "${REMOTE}:${FILE}" "${DEST}/"
|
||||
done <<< "$FILES"
|
||||
|
||||
echo "Copied to ${DEST}:"
|
||||
|
||||
Reference in New Issue
Block a user