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 8237589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:31:09+00:00 2026-06-07T19:31:09+00:00

I want to backup my ubuntu filesystem, and I wrote this little script. It

  • 0

I want to backup my ubuntu filesystem, and I wrote this little script. It is very basic, but being my first try I am afraid to do mistakes. And since it will take few hours to complete to see results, I think it is better to ask you as experienced programmers if I did something wrong.

I’m particularly interested in > will that record output of mv or will it output also results of tar?
Also variables inside tar command is it correct way?

#!/bin/bash

mybackupname="backup-fullsys-$(date +%Y-%m-%d).tar.gz"

{ time tar -cfpzv $mybackupname --exclude=/$mybackupname --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media --exclude=/dev / && ls -gh $mybackupname && mv -v $mybackupname backups/filesystem/ ; } > backup-system.log

exit

Anything I should know before I run this?

  • 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-06-07T19:31:10+00:00Added an answer on June 7, 2026 at 7:31 pm

    Sandro, you might want to consider spacing things out in your script and producing individual errors. Makes things much easier to read.

    #!/bin/bash
    
    mybackupname="backup-fullsys-$(date +%Y-%m-%d).tar.gz"
    
    # Record start time by epoch second
    start=$(date '+%s')
    
    # List of excludes in a bash array, for easier reading.
    excludes=(--exclude=/$mybackupname)
    excludes+=(--exclude=/proc)
    excludes+=(--exclude=/lost+found)
    excludes+=(--exclude=/sys)
    excludes+=(--exclude=/mnt)
    excludes+=(--exclude=/media)
    excludes+=(--exclude=/dev)
    
    if ! tar -czf "$mybackupname" "${excludes[@]}" /; then
      status="tar failed"
    elif ! mv "$mybackupname" backups/filesystem/ ; then
      status="mv failed"
    else
      status="success: size=$(stat -c%s backups/filesystem/$mybackupname) duration=$((`date '+%s'` - $start))"
    fi
    
    # Log to system log; handle this using syslog(8).
    logger -t backup "$status"
    

    If you wanted to keep debug information (like the stderr of tar or mv), that could be handled with redirection to a tmpfile or debug file. But if the command is being run via cron and has output, cron should send it to you via email. A silent cron job is a successful cron job.

    The series of ifs causes each program to be run as long as the previous one was successful. It’s like chaining your commands with &&, but lets you run other code in case of failure.

    Note that I’ve changed the order of options for tar, because the thing that comes after -f is the file you’re saving things to. Also, the -p option is only useful when extracting files from a tar. Permissions are always saved when you create (-c) a tar.

    Others might wish to note that this usage of the stat command works in GNU/Linux, but not other unices like FreeBSD or Mac OSX. In BSD, you’d use stat -f%z $mybackupname.

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

Sidebar

Related Questions

I want to backup the database as gzip, but it doesn't work. This is
I want to check the integrity of a backup of a Ubuntu disk, copied
I want to write simple script to copy/backup directory then remove on server startup.
I want to backup my web site regularly but instead of backup my files
I want to backup my database using mysql dump. This is the code I
I'm trying a script to backup a volume automatically. I follow this EBS-Snapshot.sh script
I want to make a database backup with this C# code: connect = new
I want to take backup or restore of my oracle database through .Net code.
I want to take backup of BugTracker.Net hosted on my local and restore it
I want to keep backup of my database and import it into different System?

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.