Category Archives: Linux
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
Copy from folder to folder preserving everything
Either use
sudo cp -rp /home/folder /media/backup/folder
sudo cp -a /home/folder /media/backup/folder (UPDATE: use this one!!!preserves everything)
Or use:
rsync -avz
-p same as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST]
preserve the specified attributes (default: mode,ownership,timestamps),
if possible additional attributes: context, links, xattr, all
Source: https://unix.stackexchange.com/questions/43605/how-do-i-copy-a-folder-keeping-owners-and-permissions-intact
Linux – copy all files from one folder to another with hidden (.dot) files
Simple, use:
cp -r /source/. /destination
This command will transfer all files including hidden ones (for example I usually need .htaccess for my sites to be transfered as well).