Zálohování
Z Wiki UnArt Slavičín
Pomocí BackupPc
Server
Klient
Windows
Linux
# nainstujeme rsync, wget a sudo apt-get install rsync wget sudo # přidáme uživatele backuppc bez hesla adduser -q --disabled-password --gecos "" backuppc # přidáme mu práva spouštět rsync jako root echo "backuppc ALL=NOPASSWD: /usr/bin/rsync" >> /etc/sudoers # staneme se jím :-) su backuppc # a stáhneme si SSH veřejný klíč cd && mkdir .ssh && chmod 700 .ssh && cd .ssh && wget http://freenetis.slfree.net/backuppc/authorized_keys && chmod 600
Pomocí skriptu
Zálohovací skript Romana Ševčíka napsaný pro vyuka.fai.utb.cz:
DST_DIR_TMP="/var/backup" DST_DIR="/backup" PASSWORD="pass" SPACE=$'\n' IFS=$'\n' IP="sip.icamp.eu" USER="root" echo "$SPACE" echo "Ulozeni datatabaze $SPACE" if ! [ -d "$DST_DIR_TMP" ] ; then # kontrola existence adresare v cilovem adresari, pripadne jeho vytvoreni echo "Vytvarim adresar$DST_DIR_TMP" mkdir $DST_DIR_TMP fi cd "$DST_DIR_TMP" date > datum +"%A" read DAT < datum rm datum mkdir "$DST_DIR_TMP"/daily_"$DAT" cd "$DST_DIR_TMP"/daily_"$DAT" for row in $(mysql -N --password="$PASSWORD" -u root <<<'show databases') do ( IFS=$'\t' cols=($row) echo "Ukladam databazi ${cols[0]} do souboru ${cols[0]}.sql" mysqldump --databases --quick --add-drop-table --add-locks --extended-insert --lock-tables -u root --password="$PASSWORD" "${cols[0]}" >"${cols[0]}".sql echo "Hotovo... $SPACE" ) done cd "$DST_DIR_TMP" echo "Balim do "$DST_DIR_TMP"/daily_"$DAT".tar.bz2" tar cjvf "$DST_DIR_TMP"/daily_"$DAT".tar.bz2 daily_"$DAT" echo "Hotovo... $SPACE" cd .. ssh "$USER"@"$IP" 'mkdir -p /backup/eric/Sunday/database' ssh "$USER"@"$IP" 'mkdir -p /backup/eric/Monday/database' ssh "$USER"@"$IP" 'mkdir -p /backup/eric/Tuesday /database' ssh "$USER"@"$IP" 'mkdir -p /backup/eric/Wednesday/database' ssh "$USER"@"$IP" 'mkdir -p /backup/eric/Thursday/database' ssh "$USER"@"$IP" 'mkdir -p /backup/eric/Friday/database' ssh "$USER"@"$IP" 'mkdir -p /backup/eric/Saturday/database' echo "Posilam zalohu daily_"$DAT".tar.gz na $IP" scp "$DST_DIR_TMP"/daily_"$DAT".tar.bz2 "$USER"@"$IP":/backup/eric/"$DAT"/database rm -r "$DST_DIR_TMP"/daily_"$DAT" rm -r "$DST_DIR_TMP" echo "Synchronizuju lokalni adresar /var/www s adresarem na $IP" ssh "$USER"@"$IP" 'mkdir -p /backup/eric/Sunday//data/var/www' ssh "$USER"@"$IP" 'mkdir -p /backup/eric/Monday/data/var/www' ssh "$USER"@"$IP" 'mkdir -p /backup/eric/Tuesday/data/var/www' ssh "$USER"@"$IP" 'mkdir -p /backup/eric/Wednesday/data/var/www' ssh "$USER"@"$IP" 'mkdir -p /backup/eric/Thursday/data/var/www' ssh "$USER"@"$IP" 'mkdir -p /backup/eric/Friday/data/var/www' ssh "$USER"@"$IP" 'mkdir -p /backup/eric/Saturday/data/var/www' rsync -av -e ssh --delete /var/www/ "$USER"@"$IP":/backup/eric/"$DAT"/data/var/www echo "Backup of data from $DAT has been succesfuly sent to $IP." | mail -s "Backup" dulik@fai.utb.cz -v echo "Koncim... $SPACE"