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

User rsync to rsync the data.

  1. Assumptions / Preparation:
    1. Remote server (I use OpenWRT in this case)
      1. OpenWRT can successfully auto-mount the USB external harddisk.
      2. A "backup" user has been created in OpenWRT.
      3. To create a group and user:
        /etc/passwd: USER:x:1000:1000:GROUP:/home/backup:/bin/false
        /etc/group: GROUP:x:1000:
      4. Manually update a new password:
        passwd USER
      5.  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.)
        1. mkdir /home/backup
        2. chown backup:backup /home/backup 
      6. Rsync installed
    2.  Local server (OwnCloud)
      1. Rsync installed
  2. Setup SSH auto login by SSH private key, at Owncloud server:
    1. change to root user: sudo su
    2. Generate SSH private and public key:
      1. 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/
        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:
    3. Copy the public key to OpenWRT server by using ssh-copy-id:
      1. root@owncloud:~# ssh-copy-id backup@
        /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@'s password:

        Number of key(s) added: 1

        Now try logging into the machine, with:   "ssh 'backup@'"
        and check to make sure that only the key(s) you wanted were added.


    4.  At this point, the public key ( has been copied to the server.
    5. (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)
    6.  Test the auto login
      1. ssh backup@
  3. Rsync command to be run at Owncloud server:
    (Note: cannot use -p because USB drive in FAT32 cannot support permission setting)
    1.  General files (per OwnCloud recommended)
      1. rsync -rltgoD  /root/dump.bak /var/www/owncloud/config /var/www/owncloud/data backup@
    2. SQL backup
      1. mysqldump -aroot -padmin oc > /root/dump.bak OR
        mysqldump -uroot -padmin --lock-tables oc | gzip -c >/root/dump/dump.bak.gz
      2. use rsync to sync the dump file to remote server

  4. To create cron job: crontab -e


Popular Posts