Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7058189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:04:58+00:00 2026-05-28T04:04:58+00:00

How to back up all files inside directory (all tree folders and files) to

  • 0

How to back up all files inside directory (all tree folders and files) to archive and then send to ftp server? Can I do this using cronjobs? How should tar command look like to back up /home/user/ directory and all files and folders inside to /home/ with compression?


cd /my/very/interesting/and/important/directory & tar -cjf . backup.tar.bz2 –exclude & backup.tar.bz2 & sftp backup.tar.bz2 me@myserver
as far as i understand is equal to:

  1. cd /my/very/interesting/and/important/directory
  2. tar -cjf . backup.tar.bz2 –exclude
  3. backup.tar.bz2
  4. sftp backup.tar.bz2 me@myserver

    • what parameter j means in 2nd command?
    • probably there should not be a & between tar -cjf . backup.tar.bz2 --exclude AND backup.tar.bz2. Because &merges commands. Right?
    • what about password param in 4th command?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:04:58+00:00Added an answer on May 28, 2026 at 4:04 am

    A cron job issues a command. If you can do it from the command line, you can to it with cron.

    There are at least three simple ways to accomplish what you want:

    • Create a shell script and run that.
    • Write an ant build script and run that.
    • Simply stack all the needed commands after one another, separated by &&. However, I don’t recommend this, see below.

    This is an example series of skeleton commands that might be useful. This is more intended as a sketch of the concept rather than a comprehensive, working script. For instance, I’m not sure how to use sftp without having to manually enter a password, so I left that out. Look up the documentation for the commands used and figure out yourself what to use and how in your specific case, maybe you’ll even learn something along the way. 😉

    cd my-important-directory
    tar -cpvf backup.tar -C .. --exclude backup.tar* my-important-directory
    bzip2 backup.tar
    sftp backup.tar.bz2 me@myserver
    

    You could put the above commands in a shell script, or combine them into one command, like so:

    cd my-important-directory && tar -cpvf backup.tar -C .. --exclude backup.tar* my-important-directory && bzip2 backup.tar && sftp backup.tar.bz2 me@myserver
    

    This, however, is horribly ugly if you ask me. I’d go with the shell or ant script options to improve readability and avoid maintenance headaches. Those methods also make it easier to maintain in another way: you don’t have to update the crontab every time you need to make a change to the backup script, just edit the script and you’re good to go.

    The && operator

    Separating two commands with && tells bash to run the second command if and only if the first command exits with status 0, which is the standard exit code used when commands exit successfully. This may be compared to ;, which can be used to run multiple commands in succession regardless of success or failure. Using && means that the series of commands stops if something goes wrong along the way. For instance, if tar fails to create an archive, there’s no use in attempting to compress that archive afterwards.

    What really happens behind the scenes is short-circuit logic. cmd1 && cmd2 is a logic statement that says “Return true if both cmd1 and cmd2 exit with exit code 0, otherwise return false” (though true and false are actually represented by numbers). If cmd1 doesn’t exit with exit code 0, then the logic statement is already false, and the statement returns false without running cmd2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In SQL Server how do you query a database to bring back all the
All the articles I Googled on this subject are dated back in 2004-2005. Basically
Hi All, It's clear wehn I change any control and then posts back the
In my application I'm pulling back a user's feed. This contains all of that
I need to send all requests for the directory home/alphauser to backend/alphauser, but not
I moved some files from 1 directory to the other inside visual studio. Now
Every release I find it a good practice to go back and grab all
A long while back I transitioned to doing all my web application development in
I have a query that pulls back a user's feed which is essentially all
My application goes back and forth between Portrait and Landscape. I have all of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.