Link to home
Start Free TrialLog in
Avatar of Mattia Minervini
Mattia MinerviniFlag for Italy

asked on

debian web server with word press, www folder permissions (print to a file first , complete backup after)

Hi have this 2 needs, 1) is urgent.

1)      I have a debian 7.8 distro on cloud, web\ftp server (called SERVER“A”) with wordpress.
 I need to connect , and print to a file all info about www directory (owner, permissions, attribute…)
Final goal is replicate this info on a local web server (on premise, called SERVER “B”) where i’ve just copied entire www directory
I want to use SERVER “B” as a test server.
This is a short term solution

2)      For the same scenario (SERVER “A” debian on cloud , SERVER “B” debian on premise) i need to do a better backup
Now  I copy a mysql dump and html directory…stop.
I need to do a backup preserving attribute and permissions, so restore operation (on SERVER “A” or on SERVER “B”) should be faster and more efficient.
This is a long term solution

NOTE:
a)      I cannot fetch SERVER “A” vhd (cloud limitation)
b)      I need to have clear step to apply when i have to restore a backup from a server to other one to restore (Ex. Wpconfig.php ..)
c)      My final goal i write simple script to do this operation

Sorry for my english, ask me for details, thanks for your support
I select answer complete and tested
M
Avatar of marce_lito
marce_lito

Tar will copy owner and permission information for you. Do you need to back up any other configuration/data besides the www directory? Do you have access to any other folder/configuration?

Tar can be scripted and I believe it will be fairly easy to use.

Cheers,

Marcelo
Avatar of Mattia Minervini

ASKER

i need to extract these information. i need them in a text file (csv, other...)
my goal is replicate manually permissions and attribute of WWW folder in other environment.
Yeah, I thought you would like to skip manually recreating the permissions of all the files.

Are you looking for something like
ls -l /path/to/www > file-permissions.txt
?

Cheers,

Marcelo
ls -lR gives you all subdirectories as well: you may want that
ls doesn't show the path, i need output like this:

file or folder | owner | permissions | path to file or folder

this export should be created recursively (this is ok with -lR switch)
find . ! -type d|xargs ls -lU gives you output like below, identifying all files (everything that is not a folder)
-rw-r--r-- 1 dunc users        0 Oct 10  2004 ./a/b/b1/b1a/zxc
-rw-r--r-- 1 dunc users        0 Oct 10  2004 ./a/b/b1/b1b/asd
-rw-r--r-- 1 dunc users        0 Oct 10  2004 ./a/b/b2/b2a/qwe
-rw-r--r-- 1 dunc users        0 Oct 10  2004 ./a/b/b2/b2b/123
-rwxr-xr-x 1 dunc users    14979 Sep 15  2008 ./a/b/hello
-rw-r--r-- 1 dunc users        0 Oct 10  2004 ./a/c/e
-rwxr-xr-x 1 dunc users    14979 Sep 15  2008 ./a/hello

Open in new window


find . -type d|xargs ls -lUd gives you all the folders (usually called directories by Linux users - folders is Microsoft terminology). Output looks like
drwxr-xr-x  9 dunc users    4096 Dec 11  2010 ./ee071/initrd/etc/terminfo
drwxr-xr-x  2 dunc users    4096 Apr 30  2010 ./ee071/initrd/etc/terminfo/s
drwxr-xr-x  2 dunc users    4096 Dec 11  2010 ./ee071/initrd/etc/terminfo/l
drwxr-xr-x  2 dunc users    4096 Dec 11  2010 ./ee071/initrd/etc/terminfo/v
drwxr-xr-x  2 dunc users    4096 Dec 11  2010 ./ee071/initrd/etc/terminfo/a
drwxr-xr-x  2 dunc users    4096 Apr 30  2010 ./ee071/initrd/etc/terminfo/x
drwxr-xr-x  2 dunc users    4096 Apr 30  2010 ./ee071/initrd/etc/terminfo/d
drwxr-xr-x  2 dunc users    4096 Apr 30  2010 ./ee071/initrd/etc/terminfo/b

Open in new window

these seems to be ok, but i need a merge of these two commands
if i have a directory with 30 subdirectories, and go on with 45 sub-sub directories.... should be complex check all permissions,
But it is a good starting point!
thanks now i'll try a script (if i succeed in...) or a manual merge
A=$(tempfile)
find . -type d -print0|xargs -0 ls -lUd >$A
find . ! -type d -print0|xargs -0 ls -lU >>$A

Open in new window


gets a composite file with directories all together then files.
-print0 / xargs -0 makes it work with names that contain spaces.
You could sort it by sort -k 9
ok, for question 1)
i need help for question 2)
----
2)      For the same scenario (SERVER “A” debian on cloud , SERVER “B” debian on premise) i need to do a better backup
Now  I copy a mysql dump and html directory…stop.
I need to do a backup preserving attribute and permissions, so restore operation (on SERVER “A” or on SERVER “B”) should be faster and more efficient.
This is a long term solution
----

in which way i can make a backup preserving rights on folder and files?
thanks!
Tar will do that. Have you looked at it? What is your problem with using tar?
I'm using tar -cpzf "${_bck}" /var/www/html/
but when i restore this backup i have a permissions problem.
For this reason i'm looking to a way to print to file all permissions....
What is the permissions problem exactly?
Does it go away if you restore with -U option (remove each file prior to extracting over it)
problem is this:
i make a backup with tar from a server A
then i try to restore the backup manually in a server B

Server A and server B are two server with debian 7 32 bit; they are similar (same roles, same os, same wordpress installed....) but they aren't identical

So when i use wordpress, i can see a strange behavior of some components (like galley, thumbnails not displayed...)
Webmaster told to me to check permissions , owner, group etc etc..
I check permissions on Server A and on Server B, they seems to be equal!
I created the same user on servers, but i have fear MATTIA on server A is not considered the SAME user of MATTIA on server B.

For this reason i 'm look for a way to print permissions of server A and permissions of Server B , to make a manual comparison
Then, i would make a script ...
Sorry for my english and for confusion.
Thanks
M
ASKER CERTIFIED SOLUTION
Avatar of Duncan Roe
Duncan Roe
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In case you are wondering why this all looks so difficult, it's because you're not using nis (Network Information Services). It takes care of synchronising uids between systems but otherwise is a PITA IMHO and I suggest you steer clear of it.
server A and server B are in two different environment
Understood, but you still must make the user IDs match
hi, sorry for late..
this is an update maybe positive.
Now SERVER B (local test environment) is a perfect copy of SERVER A (cloud production environment)
This is now possible cause i've changed cloud profile to a better one that give features to export vhd.
two server are now identical, so also user and UID are identical.

On SERVER A this script is running:

#obtain week number
_dow="$(date +%u)"
_bck="/var/www/backup_sito/sito_web_${_dow}.tgz"
#echo "${_bck}"
tar -cpzf "${_bck}" /var/www/html/
mysqldump --user='root' --password='password_di_root' nome_database > /path_destination/name_file.sql

So i have a backup of www folder and mysql db.
what i have to do:
- make a modify on SERVER A
- make a backup (www folder and mysql)
- put backup on SERVER B (changing www folder manually and restoring mysql db)
- see if first modify is ok on SERVER B

It's ok in your opinion?
thanks
nanoweb
Looks OK to me
problem was different uid. now i have mirrored server, so user is identical