Creare procedura di backup in ssh da Linux su server Windows
Obiettivo
Si vuole fare il backup di una macchina linux su un archivio tar depositato su un server Windows 2000. Questo archivio deve essere creato completamente PRIMA della partenza del backup su nastro del server windows, e verrà sovrascritto ogni giorno.
Impostazione Policy di Login Locale
Normalmente gli utenti non possono fare login in locale sul server.
Creazione del Gruppo LogonLocally
Dalla console "Active Directory Users and Computer" creare il gruppo tipo "Security" che si chiamerà "LogonLocally"
start %WINDIR%\system32\dsa.msc
Oppure creare il gruppo eseguendo:
net group LogonLocally /add
Impostazione della Policy per "Logon Locally"
Come indicato in Assign "Log On locally" Rights to Windows Domain Controller:
1. Click Start, click Run, type mmc, and then press ENTER.
mmc
2. Click Console, and then click Add/Remove Snap-in, click Add, and then double-click Group Policy snap-in.
3. Click Browse for the group policy object, and then double-click the folder for your domain controller.
4. Double-click Domain Controllers.domain.tld , Default Domain Controllers Policy, click Finish, click Close, and then click OK.
5. Click Default Domain Controllers Policy, double-click the Computer Configuration branch to expand it, and then double-click the Windows Setting branch to expand it.
6. Double-click the Security Settings branch to expand it, and then double-click the Local Policies branch to expand it.
7. Double-click the User Rights Assignment branch to expand it, double-click the Log On Locally branch to expand it, and then click Add.
8. Click the users or groups you want to add, click OK, and then click OK.
9. Quit the Group Policy Editor snap-in by clicking Console, clicking Exit, and then clicking No.
10. In order for the change to apply immediately, open a command prompt and type the following command:
secedit /refreshpolicy machine_policy
NOTE: If you want the policy to apply immediately to all domain controllers, run the command on each domain controller after successful replication has occurred.
11. The command typed in step 10 will generate an Event ID 1704 in the Application log of Event Viewer. Confirm the presence of the event.
NOTE: You do not have to save the console settings for the change to take effect. Active Directory replication must also occur between all domain controllers, and this could take up to 3 hours unless replication is forced.
SALTARE
Dalla console
Start/Programs/Administrative Toosl/Domain Controller Security Policy
(non "Domain Security Policy") selezionare:
Windows Settings/Security Settings/Local Policies/User Rights Assignment/Logon Locally
oppure eseguire:
start %WINDIR%/system32/dcpol.msc
ed aggiungere il gruppo precedentemente creato
DOMINIO\LogonLocally
Impostazione della Policy Locale
Dalla console
Start/Programs/Administrative Toosl/Local Security Policy
oppure:
start %WINDIR%\system32\secpol.msc
selezionare
Security Settings
fare Tasto Destro "Reload"
selezionare
Security Settings/Local Policies/User Rights Assignments/Logon Locally
Aggiungere il gruppo precedentemente creato
DOMINIO\LogonLocally
e spuntare
Local Policy Settings
Verificare che anche "Effective Policy Settings" abbia la spunta (in grigio).
RICOMINCIARE
Creazione utente Windows
Sul server windows creare un utente chiamato "firewall" con password temporanea "password"
net user firewall password /add
Assegnarlo al gruppo "LogonLocally":
net group LogonLocally firewall /add
Aggiornare l'elenco utenti di cygwin da prompt cygwin:
mv /etc/passwd /tmp mv /etc/group /tmp /etc/postinstall/passwd-grp.sh.done cat /etc/passwd | grep firewall
Sul server, sloggarsi come "administrator" e fare login come "firewall" con password "password" per creare il profilo locale.
Avviare
c:\cygwin\bin\cygwin.bat
per creare la home directory
Creare la cartella ~/.ssh facendo da prompt cygwin:
ssh localhost
Sloggarsi come "firewall" e riloggarsi come administrator
Creazione chiavi per root
Se sulla macchina linux root non dispone già di una propria coppia di chiavi, generarne una senza password con il comando:
ssh-keygen -t rsa
Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: 71:ff:e8:f0:da:23:6b:22:aa:62:ec:d8:bf:52:24:3c root@fire
Copiare la chiave pubblica sul server windows autenticandosi come user "firewall" con passowrd "password":
scp /root/.ssh/id_rsa.pub firewall@windows_server:/home/firewall/.ssh/authorized_keys
Disabilitare account windows "firewall"
Sul server windows disabilitare l'account dell'utente windows "firewall" per impedirne l'uso e consentire solo l'accesso via ssh, facnedo tasto destro
"Disable Account"
L'account "firewall" apparirà con una crocetta rossa
Oppure:
net user firewall /active:no
Verifica del funzionamento dell'accesso ssh con chiave rsa
Dalla macchina linux deve essere possibile accedere alla macchina windows via ssh senza bisogno di inserire la password:
ssh firewall@windows_server
Preparazione della cartella di backup
Sulla macchina windows da prompt cygwin, scegliere il percorso in cui posizionare il backup, e creare il link corrispondente in /mnt. Ad esempio se si decide di mettere il backup in E:\backup_firewall:
mkdir -p /mnt && ln -sf /cygdrive/e /mnt/e && mkdir -p /mnt/e/backup_firewall && chmod ugo=rwX /mnt/e/backup_firewall
Creazione delllo script di backup
Sulla macchina linux, creare lo script di backup (cambiare il nome del server ed il percorso di destinazione dell'archivio tar sul server windows):
cat > /root/bin/backup-remoto <<'EOFile' WINDOWS_SERVER='192.168.0.100' TAR_PATH='/mnt/d/backup_firewall' echo $(date) - Inizio Backup >> /var/log/backup.log cd / # Notare le doppie virgolette nel comando ssh per usare la variabile # $TAR_PATH definita su linux e passata a windows tar clf - . | ssh firewall@$WINDOWS_SERVER "cat - | bzip2 -9 > $TAR_PATH/fire.tar.bz2" echo $(date) - Fine Backup >> /var/log/backup.log EOFile chmod 755 /root/bin/backup-remoto
Modificare le variabili nello script di backup:
vi /root/bin/backup-remoto
Test dello script
Testare lo script da linux:
time /root/bin/backup-remoto
Annotare il tempo necessario al completamento del lavoro.
Verifica dell'archivio creato
Testare lo scompattamento sulla macchina linux
export WINDOWS_SERVER='192.168.0.100' export TAR_PATH='/mnt/d/backup_firewall' cd /tmp mkdir restore cd restore ssh firewall@$WINDOWS_SERVER "cat $TAR_PATH/fire.tar.bz2" | cat | tar -tvjf -
Schedulazione dello script su Linux
Schedulare lo script su linux, in anticipo sufficiente perchè sia terminato prima dell'inizio del backup su nastro di windows.
cat > /etc/cron.d/backup-remoto <<'EOFile' #m h dom mon dow user command 0 20 * * * root /root/bin/backup-remoto > /dev/null EOFile