Join the community today
Become a Member

tar -p parameter error

Discussion in 'System Administration' started by pamamolf, Oct 10, 2014.

  1. pamamolf

    pamamolf Premium Member Premium Member

    4,084
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    2:54 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    Hi


    When i try to backup using this:
    tar -zcfp /home/backup/forumfiles_$(/bin/date +%Y-%m-%d).tgz public

    i am getting this error:
    /home/backup/forumfiles_2014-10-10.tgz: Cannot stat: No such file or directory

    and when i remove the p from parameters is fine but i want to get backups using p (preserve permissions) :(
    Any ideas how can i fix this?

    Thanks
     
  2. eva2000

    eva2000 Administrator Staff Member

    54,606
    12,225
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,794
    Local Time:
    10:54 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    order matters
    Code:
    tar -cpvzf
     
  3. pamamolf

    pamamolf Premium Member Premium Member

    4,084
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    2:54 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    Ok thanks :)
     
  4. pamamolf

    pamamolf Premium Member Premium Member

    4,084
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    2:54 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    Is there anyway to create a folder using the date (/bin/date +%d-%m-%Y) and add there all backups from databases and forum files?

    So i can get :

    /backup/22-10-2014/databases and files here from that day
    /backup/23-10-2014/databases and files here from that day


    #!/bin/bash
    # Edit the variables below
    DBNAME="name_db"
    DBUSER="user_db"
    DBPASSWD="123456789"
    BACKUPDIR="/backup"
    PUBLICFOLDER="/home/nginx/domains/mydomain.com"
    /usr/bin/mysqldump $DBNAME -u $DBUSER -p$DBPASSWD > $BACKUPDIR/database.sql
    cd $BACKUPDIR
    /bin/tar -zcf database_$(/bin/date +%d-%m-%Y).tgz database.sql
    cd $PUBLICFOLDER
    /bin/tar -cpvzf $BACKUPDIR/sitefiles_$(/bin/date +%d-%m-%Y).tgz public
    sleep 2
    rm $BACKUPDIR/database.sql

    How can i do this please?

    Thanks
     
  5. eva2000

    eva2000 Administrator Staff Member

    54,606
    12,225
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,794
    Local Time:
    10:54 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Google has your answers as does reading links at Create a bash script | Centmin Mod Community within that thread

    hint make date a variable and append it to BACKUPDIR variable's value - you can check Centmin Mod's own code or /addons/*.sh files for clues ;)

    other members here are free to offer advice, but this is going beyond Centmin Mod's provided as policy for myself.
     
  6. pamamolf

    pamamolf Premium Member Premium Member

    4,084
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    2:54 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    Ok thanks i will try it :)
     
    Last edited: Oct 10, 2014
  7. pamamolf

    pamamolf Premium Member Premium Member

    4,084
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    2:54 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    Also in the net the most scripts start like:

    #/bin/bash
    and not like mine:
    #!/bin/bash
    is this a problem?
     
    Last edited: Oct 10, 2014
  8. pamamolf

    pamamolf Premium Member Premium Member

    4,084
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    2:54 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    I found the answer for the above so ignore it :)
     
    Last edited: Oct 10, 2014
  9. eva2000

    eva2000 Administrator Staff Member

    54,606
    12,225
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,794
    Local Time:
    10:54 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    digitalocean vps for 4 hrs only costs US$0.007x4 = US$0.028 enough time for quite a bit of testing ;)
     
  10. pamamolf

    pamamolf Premium Member Premium Member

    4,084
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    2:54 AM
    Nginx-1.25.x
    MariaDB 10.3.x
    Ok thanks :)

    Can you recommend me if i must use the sleep command in any other place to avoid any problems?

    Also is there any specific reason to use verbose on a bash script -v as you recommend me?

    tar -cpvzf

    Thanks
     
    Last edited: Oct 10, 2014