I'm trying to create a splitted TAR file and reading the progress by checking the size of the directory. (I cannot use PV command).
Can someone explain me why if in tarService.java I change the command to:
String cmd="su -c tar -cp -C /dev . | split -b 1G -a 3 - "+ fname;
The process in MainActivity never log anything until the other process is finished, while with:
String cmd="su -c tar -cpf " + fname + " -C /dev .";
It works!
Take care in both cases the tar file is created.
MainActivitiy.java
public void startBackup(View v){
back= new BackgroundTask().execute();
}
private class BackgroundTask extends AsyncTask<Void, Integer, String> {
@Override
protected String doInBackground(Void... arg0) {
backup = new Intent(MainActivity.this, tarService.class);
backup.putExtra("fname", "test.tar);
status=999;
startService(backup);
while (status == 999) {
try {
Process process = Runtime.getRuntime().exec("du -sk /dev");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null) {
Log.d(TAG,line);
}
}
}
}
}
tarService.java
protected void onHandleIntent(Intent i) {
try{
location=i.getStringExtra("location");
fname=i.getStringExtra("fname");
// THIS WORKS
String cmd="su -c tar -cpf " + fname + " -C /dev .";
Process process = Runtime.getRuntime().exec(cmd);
int code=process.waitFor();
Intent intent = new Intent("BackupProcess");
intent.putExtra("status", code);
Log.d(TAG,Integer.toString(code));
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
} catch (IOException e) {
Log.e(TAG, e.getMessage());
throw new RuntimeException(e);
}
}
SOLVED
There was a code error, I was passing to du
command the file name too, but with split the filename is different.