Backup Owncloud to Remote Server
Issue: To make my OwnCloud server for Production, data must be backup off the original server.
For remote server, I use OpenWRT with an external HDD in this sample
Approach:
User rsync to rsync the data.
Steps:
For remote server, I use OpenWRT with an external HDD in this sample
Approach:
User rsync to rsync the data.
Steps:
- Assumptions / Preparation:
- Remote server (I use OpenWRT in this case)
- OpenWRT can successfully auto-mount the USB external harddisk.
- A "backup" user has been created in OpenWRT.
- To create a group and user:
/etc/passwd: USER:x:1000:1000:GROUP:/home/backup:/bin/false
/etc/group: GROUP:x:1000:
/etc/shadow:
USER:RANDOMSTUFWillBeUpdatedWithPasswd:16666:0:99999:7::: - Manually update a new password:
passwd USER - To create a user home directory:
(Note: the home directory must not be on USB drive in order to use SSH auto login by SSH key.) - mkdir /home/backup
- chown backup:backup /home/backup
- Rsync installed
- Local server (OwnCloud)
- Rsync installed
- Setup SSH auto login by SSH private key, at Owncloud server:
- change to root user: sudo su
- Generate SSH private and public key:
- root@owncloud:~# ssh-keygen
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:
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx root@owncloud
The key's randomart image is: - Copy the public key to OpenWRT server by using ssh-copy-id:
- root@owncloud:~# ssh-copy-id backup@192.168.1.1
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
backup@192.168.1.1's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'backup@192.168.1.1'"
and check to make sure that only the key(s) you wanted were added.
root@owncloud:~#
- At this point, the public key (id_rsa.pub) has been copied to the server.
- (Note: if you have old RSA key generated before and changed new key, you need to remove old key at ~/.ssh/authorized_keys at OpenWRT server)
- Test the auto login
- ssh backup@192.168.1.1
- Rsync command to be run at Owncloud server:
(Note: cannot use -p because USB drive in FAT32 cannot support permission setting) - General files (per OwnCloud recommended)
- rsync -rltgoD /root/dump.bak /var/www/owncloud/config /var/www/owncloud/data backup@192.168.1.1:/mnt/sda1/Backup/owncloud
- SQL backup
- mysqldump -aroot -padmin oc > /root/dump.bak OR
mysqldump -uroot -padmin --lock-tables oc | gzip -c >/root/dump/dump.bak.gz - use rsync to sync the dump file to remote server
- To create cron job: crontab -e
Comments