Backup script – simple

If you want to make backups all of your server files (home dir or whatever) you should first make connection without passwords (using ssh).

First choose username you will be using like user981129, make it in server A (with backups). Then do this:

ssh-keygen -t rsa

You have now .ssh folder with public key (id_rsa.pub). Now go to the second server (server B) where backups will be transferred. Go to the /home/someuser and type:

mkdir .ssh; vi authorized_keys;

and then copy .ssh/id_rsa.pub from server A to authorized_keys.

Then on server B chmod .ssh 700; chmod .ssh/authorized_keys 640;

Then on server A make file with chmod a+x something like in /home/user981129:

vi backup.sh

and then paste this:

#!/bin/bash
NOW=$(date +"%m-%d-%Y")
SER="ip of the server where you are transfering files or nameserver"
FILE="backup.$NOW.tar.gz"
echo "Backing up data, please wait..."
rsync -avz /home/user981129/admin_backups/admin.root.admin.tar.gz someuser@ipofserverforbackup:/home/someuser/backups/$SER/$NOW/

Then open crontab -e and paste this:

0 3 * * * /home/user981129/backup.sh >/dev/null 2>&1

YOU ARE READY TO GO

edit: this post is for me, to speed things up when needed

Leave a Reply

Your email address will not be published. Required fields are marked *