Help me with rsync task

Status
Not open for further replies.

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
I'm looking for someone to help me with the correct syntax to set up an rsync task to archive the contents of a folder, add the date to the file name and move it to another location. I've been searching on google so much for the last 3 days my head is starting to spin.

What I'm trying to do is backup 2 directories in a jail to another dataset. I've already set up a daily sync task that is working just fine using the command below:

Code:
rsync -av --delete /mnt/RAIDZ2_1/jails/phpbb3013/usr/local/www/nginx/phpBB3 /mnt/RAIDZ2_1/forumbackup/daily
rsync -av --delete /mnt/RAIDZ2_1/jails/phpbb3013/var/db/mysql /mnt/RAIDZ2_1/forumbackup/daily


What I'm having trouble with is setting up a second task to run weekly that will take the contents of the sync'd directory above named "daily" and zip them up in an archive with the date included in the file name and move them to the directory /mnt/RAIDZ2_1/forumbackup/archive so that it doesn't get overwritten every week when the task runs. If that's not possible is it possible to move them to a new directory with the date on a weekly schedule? Either way would work for me, I just want to automate it so I don't have to babysit it and do it manually. I figure I can prune the old files manually on occasion as needed.

Can someone please help me with this?

Thanks.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
I think rsync can't do this but you can easily do it with the commands mv and date and probably a few others needed too ;)
 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
Well supposedly you can, I just don't know the commands to get it to work.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Ok, let me see what I can find.

You really want to do this with rsync or some generic commands is also ok?
 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
Whatever works to archive, rename and move via a cron task so it's automated.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Sorry for the delay, I lost some long time with an user in the French section who doesn't like the FreeNAS minimum requirements trying to explain why the requirements are what they are and that it's stupid to use non-ECC RAM...

I managed to use only one command:
Code:
tar -jcf "/root/test/archive/`date '+%Y-%m-%d_%H-%M-%S.bz2'`" -C "/root/test/" "daily"


Of course you need to replace the paths by the absolute paths you want. We need to use the -C "/root/test/" "daily" form because it's not a good idea to include absolute path in a archive (when you decompress it it will use the absolute path and if the absolute path begins with /etc/... or /bin/... for example you'll don't like the result...) ;)

To decompress an archive use this command: tar -jxf the name_of_the_archive

It'll decompress it in this form: directory_where_you_use_the_tar_-jxf_command/daily/the_files_will_be_here so don't use it in a directory with an existing daily sub-directory :)
 
Last edited:

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
Thank you, will give this a try when I get home from work today.
 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
Ok it worked but it didn't end up where I though it would. This is the command I used:

Code:
tar -jcf "/mnt/RAIDZ2_1/forumbackup/daily/`date '+%Y-%m-%d_%H-%M-%S.bz2'`" -C "/mnt/RAIDZ2_1/forumbackup/Weekly" "daily"


And it ended up in /mnt/RAIDZ2_1/forumbackup/daily

Why did it end up in the "daily" folder and not the "weekly" folder?

Edit: I guess I should be a little more clear, I'm trying to create an archive of the contents of the daily folder and move that archive to the weekly folder.
 
Last edited:

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Because you've swapped the two directories :)

Re-read the command in my previous post, the first directory is the destination directory and the second is the source ;)
 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
Ok when I change the directories around in my command to this:

Code:
tar -jcf "/mnt/RAIDZ2_1/forumbackup/weekly/`date '+%Y-%m-%d_%H-%M-%S.bz2'`" -C "/mnt/RAIDZ2_1/forumbackup/daily/" "daily"


I get an error:

Code:
tar: daily: Cannot stat: No such file or directory
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
It's because you need to use this: -C "/mnt/RAIDZ2_1/forumbackup/" "daily" (it's the same as using "/mnt/RAIDZ2_1/forumbackup/daily" but it doesn't put the absolute path in the archive, I explained all that in my post of yesterday) ;)
 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
IT WORKS!!!!!!

BiduleOhm thank you so much for helping me with this. This is literally the last piece of the puzzle on my project I'm working on.

This forum ROCKS!
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
No problem, you're welcome ;)
 
Status
Not open for further replies.
Top