1

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.

  • 1
    you need to escape % sign with backslash – bac0n Feb 14 at 17:32
1
  1. Use the -C option, like this: tar -zcC /home/username -f output.tgz .mozilla
  2. Read this answer.
  3. Use the -p option.
  4. I do not understand your question.
| improve this answer | |
  • 1
    The answer to (4) is no in a user crontab (including that of the root user, as accessed via sudo crontab -e) but yes in the system crontab file /etc/crontab – steeldriver Feb 14 at 17:44
  • 1
    @Jags please also note bac0n's comment above regarding the percent signs - see for example Unable to execute command in cron – steeldriver Feb 14 at 18:00
  • @Jags he order of options isn't critical but fwiw I would probably write it as tar -czf /home/username/Dropbox/Backups/Firefox_Profile_$(date "+\%b_\%d_\%Y_\%H-\%M").tgz -C /home/username/ .mozilla/. Don't forget the leading / on /home. – steeldriver Feb 14 at 18:16
1

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

1 0 * * * tar -I 'gzip -9' -pcf /home/username/Dropbox/Backups/Firefox_Profile_$(date "+\%b_\%d_\%Y_\%H-\%M").tgz -C /home/username/ .mozilla/ && echo "Firefox profile backed up on:" `date` >> /home/username/jobs

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.