You are not logged in.

#1 2012-07-20 08:05:35

DSpider
Member
From: Romania
Registered: 2009-08-23
Posts: 2,273

[SOLVED] Can this script use a HEREDOC instead of an external file?

https://wiki.archlinux.org/index.php/Fu … ith_a_list

Is there a way to "<<" the "backup.lst" file inside "backup.sh"?

Last edited by DSpider (2012-07-21 11:34:31)


"How to Succeed with Linux"

I have made a personal commitment not to reply in topics that start with a lowercase letter. Proper grammar and punctuation is a sign of respect, and if you do not show any, you will NOT receive any help (at least not from me).

Offline

#2 2012-07-20 10:09:04

aesiris
Member
Registered: 2012-02-25
Posts: 97

Re: [SOLVED] Can this script use a HEREDOC instead of an external file?

This should work, but I feel is "wrong".

#!/bin/bash

exec 5< <( 

cat <<EOF
here document
EOF

)

sudo sh -c "cat /proc/$$/fd/5"

Is there any way to pass a file descriptor through sudo?

Offline

#3 2012-07-20 15:28:08

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: [SOLVED] Can this script use a HEREDOC instead of an external file?

From rsync(1):

--exclude-from=FILE
              This option is related to the --exclude option, but it specifies
              a FILE that contains exclude patterns  (one  per  line).   Blank
              lines  in  the  file  and  lines  starting  with  ';' or '#' are
              ignored. If FILE is -, the list  will  be  read  from  standard
              input.
(emphasis mine)

So something like this might work (untested):

sudo sh -c "
    rsync -av --delete-excluded --exclude-from=- / $1;
    date > $1/BACKUP
" <<EOF
...
EOF

I wouldn't write it like that personally; I'd at least leave off the sudo and run the whole thing with sudo if I needed permissions. Actually I'd do a lot of things differently than that page. But that's neither here nor there.

Last edited by Trent (2012-07-20 15:30:03)

Offline

#4 2012-07-20 15:33:34

DSpider
Member
From: Romania
Registered: 2009-08-23
Posts: 2,273

Re: [SOLVED] Can this script use a HEREDOC instead of an external file?

How would you do it differently?

Because I also think it's too complicated.

Last edited by DSpider (2012-07-20 16:34:38)


"How to Succeed with Linux"

I have made a personal commitment not to reply in topics that start with a lowercase letter. Proper grammar and punctuation is a sign of respect, and if you do not show any, you will NOT receive any help (at least not from me).

Offline

#5 2012-07-21 11:34:12

DSpider
Member
From: Romania
Registered: 2009-08-23
Posts: 2,273

Re: [SOLVED] Can this script use a HEREDOC instead of an external file?

#!/bin/sh

rsync -av /* /media/Backup/bak --exclude-from=- <<-"EOF"

# Exclude list:

- /dev/*
- /proc/*
- /sys/*
- /tmp/*
- /run/*
- /mnt/*
- /media/*
- /lost+found
- /home/*/.gvfs

EOF

This works.

Couldn't manage to place the list at the top of the rsync line, so I revised my approach a bit and eventually came up with this script:

#!/bin/sh

START=$(date +%s)
rsync -av /* /media/Backup/bak --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/home/*/.gvfs}
FINISH=$(date +%s)
echo "total time: $(( ($FINISH-$START) / 60 )) minutes, $(( ($FINISH-$START) % 60 )) seconds"

touch /media/Backup/bak/"Backup from $(date '+%A, %d %B %Y, %T')"

It's simple, it's elegant and makes a lot more sense. I will replace "/media/Backup/bak" with "$1" and update the wiki.

Thank you, both.

Last edited by DSpider (2012-07-21 11:36:07)


"How to Succeed with Linux"

I have made a personal commitment not to reply in topics that start with a lowercase letter. Proper grammar and punctuation is a sign of respect, and if you do not show any, you will NOT receive any help (at least not from me).

Offline

#6 2012-07-21 14:15:59

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: [SOLVED] Can this script use a HEREDOC instead of an external file?

I was going to describe how I might do things differently, but you've found a pretty reasonable solution and I don't see a need to improve on it.

I don't do full-system backups myself.

Offline

Board footer

Powered by FluxBB