Hack Forums
Backup & Pull backup from server [TUT] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Computing (https://hackforums.net/forumdisplay.php?fid=88)
+---- Forum: Linux (https://hackforums.net/forumdisplay.php?fid=85)
+---- Thread: Backup & Pull backup from server [TUT] (/showthread.php?tid=2966127)



Backup & Pull backup from server [TUT] - Loki123 - Oct 23, 2012

I'm bored, lets start.

We are going to, take a backup of /var/www & Mysql, put it all in a tar.xz file, then pull it away from the server. Let's start.

What you need :
  • Backup script What I use
  • *nix server, *nix local-PC
  • SSH keys installed on the server (Without passphrase for crobjob.. )

Take a backup, and tell the script to put it where ever you wan't...
For my script I cronjob it like this
PHP Code

<?php 
30 6 
* * * /PATH/TO/SCRIPT/backup.sh -v -f /var/www/ -t /PATH/TO/BACKUP/PLACE/ -p PREFIX -d DATABASE -u MYSQLUSER -a MYSQLPASS 

You can also do --help for information on what that does & more does... this does it automatic at 06:30AM every day.

Ok, then you can run this on your local PC in cron :
PHP Code

<?php 
35 6 
* * * rsync -zavrR --links --rsh="ssh -l {SSH-USER}" {SERVER}:/PATH/TO/BACKUP/ON/SERVER /PATH/TO/BACKUP/STORAGE/ON/YOUR/PC 
This will copy the backup from your server to your PC and would run 06:35AM every day.
Also only take the files that are missing from your backup/storage on the PC...
You can add "--delete" after "-zavrR" to delete files after the copy.

To install a cronjob you run this line :
PHP Code

<?php 
crontab 
-e 
-e is to edit users crontab (Cronjob) file and enter your cronjob line.

Have fun. 😑


* - Fa-koff - Oct 23, 2012

Nice! Thanks for leading by example.


* - Loki123 - Oct 23, 2012

(Oct 23, 2012 03:46 PM)Fa-koff Wrote:  Nice! Thanks for leading by example.

hummm, i forgot to post in the TUT where you put the cronjob line ... 🤐
Fixxed


* - NeyZ - Oct 23, 2012

Any idea to add the key part so it becomes fully automatic and don't have to enter the password everytime. Rsync is awesome, using it on all my 14 servers.

Also, the --delete option doesn't delete the files on the main pc, only on the backup server when it is removed on the main pc. If I was right.


* - Gent - Oct 24, 2012

(Oct 23, 2012 11:25 PM)NeyZ Wrote:  Any idea to add the key part so it becomes fully automatic and don't have to enter the password everytime. Rsync is awesome, using it on all my 14 servers.

Also, the --delete option doesn't delete the files on the main pc, only on the backup server when it is removed on the main pc. If I was right.

Edit your sshd_config file and disable PAM and password authetication.

Code
PasswordAuthentication    no
UsePAM            no



* - NeyZ - Oct 24, 2012

But than you won't be able to log onto your server without a key added to your server.


* - Gent - Oct 24, 2012

(Oct 24, 2012 02:26 AM)NeyZ Wrote:  But than you won't be able to log onto your server without a key added to your server.

Isn't that the point?

Code
On local machine:

mkdir ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t rsa -C "derp@derp"
scp -p ~/.ssh/id_rsa.pub user@server:

On remote machine:

mkdir ~/.ssh
chmod 700 ~/.ssh
cat id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
mv id_rsa.pub ~/.ssh

Do what I said above after doing this. Just copy your .ssh directory to the home directory of the user you wish to enable remote connections for. To connect from other machines, just put the key in ~/.ssh on the machine you're trying to connect from.

Code
chown -R user:group /home/user/.ssh

Do this after copying it.


* - NeyZ - Oct 24, 2012

Ohhh like that, nah I know how it works. I tought you forget to add the key. But it wasn't your plan to put that in your post at all.

Nothing said ;)


* - Loki123 - Oct 24, 2012

(Oct 23, 2012 11:25 PM)NeyZ Wrote:  Also, the --delete option doesn't delete the files on the main pc, only on the backup server when it is removed on the main pc. If I was right.

That is the meaning of what I said, it would not even make sense to delete files that you just put on your local machine. 🤦‍♂


* - NeyZ - Oct 25, 2012

True, however I tought you meant that it deletes the files on your main machine and not the backup machine.