117
29
I have the following script I wrote by searching Google, and it backs up my Linux system to an archive:
#!/bin/bash
# init
DATE=$(date +20%y%m%d)
tar -cvpzf /share/Recovery/Snapshots/$HOSTNAME_$DATE.tar.gz --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media --exclude=/dev --exclude=/share/Archive /
This works, but I am wondering if I can format the script to show the command over multiple lines, something like this, so it is easy to edit later:
tar -cvpzf /share/Recovery/Snapshots/$HOSTNAME_$DATE.tar.gz
--exclude=/proc
--exclude=/lost+found
--exclude=/sys
--exclude=/mnt
--exclude=/media
--exclude=/dev
--exclude=/share/Archive
/
That way it is easier to read and edit later. Is it possible to format a Bash script this way?
1
It is recommended to use
– andrybak – 2015-01-25T10:46:00.080$(command)
instead of\
command``.Thanks guys. One last thing. There seems to be a problem with the file name portion of my script:
When I run the script now, the output file is:
If you want your actual "hostname" put it in back ticks (the tilde "~" key above tab):
/share/Recovery/Snapshots/\
hostname`_$DATE.tar.gz` – nerdwaller – 2012-11-21T03:36:54.943Anytime @JayLaCroix - Welcome to SU! – nerdwaller – 2012-11-21T03:40:28.270