I'm trying to setup a cron job to archive/backup /home/username/.mozilla/
directory and all its sub-directories, including hidden files, using tar. I like to run the job at 12:01 AM every night.
Here's what I have planned so far:
crontab -e
1 0 * * * tar -zcf /home/username/Dropbox/Backups/Firefox_Profile_$(date +%b_%d_%Y_"%H-%M").tgz home/username/.mozilla/ && echo "Firefox profile backed up on:" `date` >> /home/username/jobs
Though I have not actually setup the cron job yet, when I run this command in terminal:
tar -zcf /home/username/Dropbox/Backups/Firefox_Profile_$(date +%b_%d_%Y_"%H-%M").tgz home/username/.mozilla/
it does create a compressed archive, but upon exctraction, it creates a directory home
> username
> .mozilla
and its sub-directories.
What I am looking for is:
(1) upon extraction there would be either .mozilla
or preferably mozilla
(removing the dot), and its sub-directories, including hidden files (no home
or username
directories).
(2) is tar -zcf
the best way to get maximum compression.
(3) keep all the file permissions as it is.
(4) do I need to have [user] (which is "username") in this command: 1 0 * * * username tar -zcf
Thanks a lot.
-C
option, like this:tar -zcC /home/username -f output.tgz .mozilla
-p
option.Posting my own answer as, though fliegendewurst's answer helped me somewhat, I wasn't able to complete the command to run a cron job. Comments from bac0n and steeldriver help me figure out the rest.
What's working for me:
crontab -e
Reference for specifying the gzip compression level using
-I
option:https://superuser.com/a/1091640
Note: If Firefox is open/running at the time of running this command, you might get a message that a file was being written.