Script for directory file backup using shell position variables

Source: Internet
Author: User
Tags pack backup

Today only found that the original position variable can also play so cool!!

This is a file directory backup using the location variable:

#!/bin/bash

Date= ' Date +%f '//date output from year to month

Tar Czf $ $DATE. tar.gz $ >/dev/null 2>>/opt/$1.bak.log//pack variable package, append error to log, tar package will keep original directory, better

If [$?-eq 0] The return value is 0 for packing OK, not 0, not OK

Then #包 time pack OK append to log

echo "$ $DATE backup successfully" >>/opt/$1.bak.log

Else #包 time Package not OK append to log

echo "$ $DATE backup failed" >>/opt/$1.bak.log

Fi

~

~ and then combine the task of planning:

[Root@redhat etc]# Crontab-l

*/1 * * * */BIN/SH/SHELLSCRIPTS/BAK.SH/ETC

*/1 * * * */bin/sh/shellscripts/bak.sh/boot

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.