본문 바로가기

StackOverflow

[Android] 루팅하지 않고 앱의 데이터베이스 파일을 얻는 방법

http://stackoverflow.com/questions/2078710/android-adb-access-to-application-databases-without-root


Q루팅하지 않고 앱의 데이터베이스 파일을 얻는 방법을 아시는 분 없나요?

예를 들면, 아래와 같이 데이터베이스 파일의 경로를 알고 있습니다.


ADB는 루팅 없이 쓸 수 있다는 것을 알고 있는데, 해당 경로를 ADB를 이용하여 보려고 하면 root 권한이 필요하다고 나옵니다. 하지만 파일의 위치만 알고 있다면 루팅 권한 없이도 해당 파일에 접근할 수 있다는 이야기를 들은 적이 있습니다.

제가 하고 싶은 것은, 루팅 안된 폰에서 앱의 데이터베이스 파일을 얻은 뒤(pull), 그것을 수정하여 다시 원래 위치로 복사하는 (push) 것입니다.

저는 이 문제를 해결할 수 없는데, 제가 가진 폰이 다 루팅된 폰이라 확인할 길이 없기 때문입니다.

(질문자: Scoobler)


A: 아래 Nilhcem의 답변은 제 단말에서는 동작하지 않았는데, 그걸 조금 수정해서 동작 가능한 해결책을 만들었습니다 (그리고 아래 답변에 추천을 눌렀습니다)

adb shell
$ run-as package.name
$ cd ./databases/
$ ls -l #Find the current permissions - r=4, w=2, x=1
$ chmod 666 ./dbname.db
$ exit
$ exit
adb pull /data/data/package.name/databases/dbname.db ~/Desktop/
adb push ~/Desktop/dbname.db /data/data/package.name/databases/dbname.db
adb shell
$ run-as package.name
$ chmod 660 ./databases/dbname.db #Restore original permissions
$ exit
$ exit


(역주: 

그렇게 한 뒤에도 잘 안되는 단말도 있습니다. 이 경우 대안으로, 아래와 같은 방법이 먹히는 경우도 있습니다.

굵은 글씨는 자신에게 해당되는 패키지 명 또는 db 파일 명을 입력하면 됩니다.

adb shell

$ run-as package.name

$ cd ./databases/

$ chmod 666 ./dbname.db

[여기까지는 동일]

cp dbaname.db /sdcard/dbname.db

$ exit

$ exit


여기서, sdcard는 usb를 연결하고 윈도우 탐색기에서 해당 단말을 클릭했을 때 이용자가 볼 수 있는 첫 번째 경로입니다. Astro 파일관리자 등의 앱을 이용해서도 볼 수 있습니다. 이후 이 db 파일을 USB를 연결하여 복사하거나, 이메일로 파일 첨부를 해서 보내거나 하는 방법을 이용하여 PC로 복사한 뒤, DB 뷰어를 이용하여 확인할 수 있습니다.)

(답변자: Pilot_51)


_

Can anyone tell me, is it possible to use the ADB to pull and push a database from an app, without root privaliges on the phone?

For example, I know the location on my rooted magic and dream is:

/data/data/com.xxxx.xxxx/databases/xxxx

I know that you can use ADB without root, but when trying to use the shell - you can't view that location without root privaliges. But I have been told you can use push and pull if you know the file you want?

Basically I want to pull a database from MY app on a non rooted phone modify it and push it back on.

Only trouble I have is, the two phones I have are both root and I don't have access to a non root one to try it out.

shareeditflag


_

42down voteaccepted

While Nilhcem's answer didn't work for me, it lead me in the right direction (for that I upvoted) and I now have a working solution.

adb shell
$ run-as package.name
$ cd ./databases/
$ ls -l #Find the current permissions - r=4, w=2, x=1
$ chmod 666 ./dbname.db
$ exit
$ exit
adb pull /data/data/package.name/databases/dbname.db ~/Desktop/
adb push ~/Desktop/dbname.db /data/data/package.name/databases/dbname.db
adb shell
$ run-as package.name
$ chmod 660 ./databases/dbname.db #Restore original permissions
$ exit
$ exit
shareeditflag