Back up webserver to FreeNAS?

Status
Not open for further replies.

oguruma

Patron
Joined
Jan 2, 2016
Messages
226
I have a Ubuntu VPS hosting some Wordpress sites. I have a FreeNAS box behind my firewall at home.

I want to (securely) back up my /var/www directory and databases to my FreeNAS.

I know I can do a local backup and just Rsync Pull from the NAS, but this takes up valuable space on the VPS because I have to have a local backup.

Is there a way to script this as such that my NAS will tarball the /var/www and sql dumps then pull them back to itself?
 

guermantes

Patron
Joined
Sep 27, 2017
Messages
213
I don't know about tarballing, but you could pull /var/www to your local computer without taking up VPS-space using
rsync -avzh user@remote:/var/www/* /local/dir/. Have cron spit out sql dumps beforehand.
 

oguruma

Patron
Joined
Jan 2, 2016
Messages
226
I don't know about tarballing, but you could pull /var/www to your local computer without taking up VPS-space using
rsync -avzh user@remote:/var/www/* /local/dir/. Have cron spit out sql dumps beforehand.

The issue I see is that if the database ends up out of sync with the /var/www directory since the database won't necessarily be in sync with all of the files with the files in /var/www (somebody adds a post after the dump but before the FreeNAS rsync).
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
Do you have space on the vps for a very temporary backup? If so, something like this, running on the vps, should do the trick:
Code:
#!/bin/bash
mysqldump --lock-tables wordpress > /tmp/wordpress-mysql-`date +"%Y%m%d"`.sql
tar -cvjSf /tmp/wordpress-backup-`date +"%Y%m%d"`.tar.bz2 /var/www /tmp/wordpress-mysql-`date +"%Y%m%d"`.sql
scp /tmp/wordpress-backup-`date +"%Y%m%d"`.tar.bz2 user@freenas_ip:/path/to/storage
rm -f /tmp/wordpress-backup-`date +"%Y%m%d"`.tar.bz2 /tmp/wordpress-mysql-`date +"%Y%m%d"`.sql


This does rely on your vps being able to access your FreeNAS box, perhaps over a VPN connection.
 
Status
Not open for further replies.
Top